@mastra/loggers 1.2.0-alpha.0 → 1.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pino.ts"],"names":["MastraLogger","pretty","pino","LogLevel"],"mappings":";;;;;;;;;;;;AAwCO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAwDA,mBAAA,CAAa;AAAA,EACtE,MAAA;AAAA,EAEV,WAAA,CAAY,OAAA,GAA2C,EAAC,EAAG;AACzD,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,MAAM,eAAA,GAAkB,OAAA;AAGxB,IAAA,IAAI,gBAAgB,OAAA,EAAS;AAC3B,MAAA,IAAA,CAAK,SAAS,eAAA,CAAgB,OAAA;AAC9B,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,iBAAA,GAAoB,QAAQ,WAAA,IAAe,IAAA;AACjD,IAAA,IAAI,YAAA,GAAsD,MAAA;AAC1D,IAAA,IAAI,CAAC,OAAA,CAAQ,yBAAA,IAA6B,iBAAA,EAAmB;AAC3D,MAAA,YAAA,GAAeC,uBAAA,CAAO;AAAA,QACpB,QAAA,EAAU,IAAA;AAAA,QACV,UAAA,EAAY,IAAA;AAAA,QACZ,MAAA,EAAQ,wBAAA;AAAA,QACR,eAAA,EAAiB,IAAA;AAAA,QACjB,aAAA,EAAe,cAAA;AAAA,QACf,UAAA,EAAY;AAAA,OACb,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,gBAAgB,CAAC,GAAG,KAAK,aAAA,EAAc,CAAE,SAAS,CAAA;AACxD,IAAA,IAAA,CAAK,MAAA,GAASC,qBAAA;AAAA,MACZ;AAAA,QACE,IAAA,EAAM,QAAQ,IAAA,IAAQ,KAAA;AAAA,QACtB,KAAA,EAAO,OAAA,CAAQ,KAAA,IAASC,eAAA,CAAS,IAAA;AAAA,QACjC,YAAY,OAAA,CAAQ,UAAA;AAAA,QACpB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A,IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,IAAA,EAAM,OAAO,CAAA;AAAA,EACjC;AAAA,EAEA,IAAA,CAAK,OAAA,EAAiB,IAAA,GAA4B,EAAC,EAAS;AAC1D,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,OAAO,CAAA;AAAA,EAChC;AAAA,EAEA,IAAA,CAAK,OAAA,EAAiB,IAAA,GAA4B,EAAC,EAAS;AAC1D,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,OAAO,CAAA;AAAA,EAChC;AAAA,EAEA,KAAA,CAAM,OAAA,EAAiB,IAAA,GAA4B,EAAC,EAAS;AAC3D,IAAA,IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,IAAA,EAAM,OAAO,CAAA;AAAA,EACjC;AACF","file":"index.cjs","sourcesContent":["import type { LoggerTransport } from '@mastra/core/logger';\nimport { LogLevel, MastraLogger } from '@mastra/core/logger';\nimport pino from 'pino';\nimport pretty from 'pino-pretty';\n\ntype TransportMap = Record<string, LoggerTransport>;\n\nexport type { LogLevel } from '@mastra/core/logger';\n\nexport interface PinoLoggerOptions<CustomLevels extends string = never> {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n mixin?: pino.MixinFn<CustomLevels>;\n customLevels?: { [level in CustomLevels]: number };\n /**\n * When false, disables pino-pretty and outputs raw JSON.\n * Useful when sending logs to aggregators like Datadog,\n * Loki, or CloudWatch that expect single-line JSON per entry.\n * @default true\n */\n prettyPrint?: boolean;\n /**\n * Override the key used for the log message.\n * Defaults to Pino's built-in 'msg' key.\n * Set to 'message' for compatibility with Google Cloud Logging,\n * Elastic Common Schema (ECS), Datadog, and AWS CloudWatch.\n * @example 'message'\n */\n messageKey?: string;\n}\n\ninterface PinoLoggerInternalOptions<CustomLevels extends string = never> extends PinoLoggerOptions<CustomLevels> {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger<CustomLevels>;\n}\n\nexport class PinoLogger<CustomLevels extends string = never> extends MastraLogger {\n protected logger: pino.Logger<CustomLevels>;\n\n constructor(options: PinoLoggerOptions<CustomLevels> = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions<CustomLevels>;\n\n // If an existing pino logger is provided (for child loggers), use it directly\n if (internalOptions._logger) {\n this.logger = internalOptions._logger;\n return;\n }\n\n const shouldPrettyPrint = options.prettyPrint ?? true;\n let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports && shouldPrettyPrint) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname,component',\n colorizeObjects: true,\n translateTime: 'SYS:standard',\n singleLine: false,\n });\n }\n\n const transportsAry = [...this.getTransports().entries()];\n this.logger = pino(\n {\n name: options.name || 'app',\n level: options.level || LogLevel.INFO,\n formatters: options.formatters,\n redact: options.redact,\n mixin: options.mixin,\n customLevels: options.customLevels,\n messageKey: options.messageKey ?? 'msg',\n },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream // undefined when prettyPrint:false → pino native JSON\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n ...(prettyStream // only add prettyStream to multistream if it exists\n ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }]\n : []),\n ]),\n );\n }\n\n /**\n * Creates a child logger with additional bound context.\n * All logs from the child logger will include the bound context.\n *\n * @param bindings - Key-value pairs to include in all logs from this child logger\n * @returns A new PinoLogger instance with the bound context\n *\n * @example\n * ```typescript\n * const baseLogger = new PinoLogger({ name: 'MyApp' });\n *\n * // Create module-scoped logger\n * const serviceLogger = baseLogger.child({ module: 'UserService' });\n * serviceLogger.info('User created', { userId: '123' });\n * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }\n *\n * // Create request-scoped logger\n * const requestLogger = baseLogger.child({ requestId: req.id });\n * requestLogger.error('Request failed', { err: error });\n * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }\n * ```\n */\n child(bindings: Record<string, unknown>): PinoLogger<CustomLevels> {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions<CustomLevels> = {\n name: this.name,\n level: this.level,\n transports: Object.fromEntries(this.transports),\n _logger: childPino,\n };\n return new PinoLogger(childOptions);\n }\n\n debug(message: string, args: Record<string, any> = {}): void {\n this.logger.debug(args, message);\n }\n\n info(message: string, args: Record<string, any> = {}): void {\n this.logger.info(args, message);\n }\n\n warn(message: string, args: Record<string, any> = {}): void {\n this.logger.warn(args, message);\n }\n\n error(message: string, args: Record<string, any> = {}): void {\n this.logger.error(args, message);\n }\n}\n"]}
1
+ {"version":3,"file":"index.cjs","names":["MastraLogger","#adapterContextRef","LogLevel","#export"],"sources":["../src/pino.ts"],"sourcesContent":["import type { LoggerTransport, LoggerAdapterContext } from '@mastra/core/logger';\nimport { LogLevel, MastraLogger, buildLogRecordData, exportTrackedException } from '@mastra/core/logger';\nimport pino from 'pino';\nimport pretty from 'pino-pretty';\n\ntype TransportMap = Record<string, LoggerTransport>;\n\nexport type { LogLevel } from '@mastra/core/logger';\n\nexport interface PinoLoggerOptions<CustomLevels extends string = never> {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n mixin?: pino.MixinFn<CustomLevels>;\n customLevels?: { [level in CustomLevels]: number };\n /**\n * When false, disables pino-pretty and outputs raw JSON.\n * Useful when sending logs to aggregators like Datadog,\n * Loki, or CloudWatch that expect single-line JSON per entry.\n * @default true\n */\n prettyPrint?: boolean;\n /**\n * Override the key used for the log message.\n * Defaults to Pino's built-in 'msg' key.\n * Set to 'message' for compatibility with Google Cloud Logging,\n * Elastic Common Schema (ECS), Datadog, and AWS CloudWatch.\n * @example 'message'\n */\n messageKey?: string;\n}\n\ninterface PinoLoggerInternalOptions<CustomLevels extends string = never> extends PinoLoggerOptions<CustomLevels> {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger<CustomLevels>;\n /** @internal Shared adapter-context ref so root and children correlate together */\n _adapterContextRef?: { current?: LoggerAdapterContext };\n}\n\nexport class PinoLogger<CustomLevels extends string = never> extends MastraLogger {\n protected logger: pino.Logger<CustomLevels>;\n // Mutable ref shared with child loggers: the root's mixin (which children's\n // pino instances inherit) reads through this ref, so attaching observability\n // to a child (e.g. `new Mastra({ logger: base.child({...}) })`) correlates\n // the records it actually logs through.\n #adapterContextRef: { current?: LoggerAdapterContext };\n\n constructor(options: PinoLoggerOptions<CustomLevels> = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions<CustomLevels>;\n this.#adapterContextRef = internalOptions._adapterContextRef ?? {};\n\n // If an existing pino logger is provided (for child loggers), use it directly\n if (internalOptions._logger) {\n this.logger = internalOptions._logger;\n return;\n }\n\n // Compose the user mixin with trace correlation. Pino mixins run\n // synchronously on every log call, so the trace fields land in the\n // native record before serialization — for ALL destinations (stdout,\n // transports, files). Trace fields win on key conflicts.\n const userMixin = options.mixin;\n const correlationMixin: pino.MixinFn<CustomLevels> = (mergeObject, level, logger) => {\n const userFields = userMixin ? userMixin(mergeObject, level, logger) : {};\n const ctx = this.#adapterContextRef.current;\n if (!ctx?.options.correlation) return userFields;\n try {\n return { ...userFields, ...(ctx.resolveTraceFields() ?? {}) };\n } catch {\n return userFields;\n }\n };\n\n const shouldPrettyPrint = options.prettyPrint ?? true;\n let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports && shouldPrettyPrint) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname,component',\n colorizeObjects: true,\n translateTime: 'SYS:standard',\n singleLine: false,\n });\n }\n\n const transportsAry = [...this.getTransports().entries()];\n this.logger = pino(\n {\n name: options.name || 'app',\n level: options.level || LogLevel.INFO,\n formatters: options.formatters,\n redact: options.redact,\n mixin: correlationMixin,\n customLevels: options.customLevels,\n messageKey: options.messageKey ?? 'msg',\n },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream // undefined when prettyPrint:false → pino native JSON\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n ...(prettyStream // only add prettyStream to multistream if it exists\n ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }]\n : []),\n ]),\n );\n }\n\n /**\n * Creates a child logger with additional bound context.\n * All logs from the child logger will include the bound context.\n *\n * @param bindings - Key-value pairs to include in all logs from this child logger\n * @returns A new PinoLogger instance with the bound context\n *\n * @example\n * ```typescript\n * const baseLogger = new PinoLogger({ name: 'MyApp' });\n *\n * // Create module-scoped logger\n * const serviceLogger = baseLogger.child({ module: 'UserService' });\n * serviceLogger.info('User created', { userId: '123' });\n * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }\n *\n * // Create request-scoped logger\n * const requestLogger = baseLogger.child({ requestId: req.id });\n * requestLogger.error('Request failed', { err: error });\n * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }\n * ```\n */\n child(bindings: Record<string, unknown>): PinoLogger<CustomLevels> {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions<CustomLevels> = {\n name: this.name,\n level: this.level,\n transports: Object.fromEntries(this.transports),\n _logger: childPino,\n _adapterContextRef: this.#adapterContextRef,\n };\n return new PinoLogger(childOptions);\n }\n\n /**\n * Adapter hook (see `AdaptableLogger` in `@mastra/core/logger`): enables\n * native trace correlation (trace_id/span_id merged into the pino record\n * via mixin, for every destination) and observability export derived from\n * the same record. Called by Mastra during setup.\n */\n __attachObservability(ctx: LoggerAdapterContext): void {\n // Shared ref: attaching to a child also enables correlation on the root\n // mixin the child's records flow through (and vice versa).\n this.#adapterContextRef.current = ctx;\n }\n\n /**\n * The adapter context lives on the ref cell shared by the whole\n * root/child family, so re-attach detection (multi-Mastra warning) must\n * key on that cell — attaching to a child re-targets the root too.\n */\n __observabilityAttachmentKey(): object {\n return this.#adapterContextRef;\n }\n\n /**\n * Export the record derived from the same native call to observability.\n * Runs regardless of pino's level filter and never throws into the caller.\n */\n #export(level: 'debug' | 'info' | 'warn' | 'error', message: string, args: Record<string, any>): void {\n const ctx = this.#adapterContextRef.current;\n if (!ctx?.options.export) return;\n try {\n // An Error passed as the args value often has no enumerable keys but\n // must still be exported (serialized by buildLogRecordData).\n const hasPayload = args instanceof Error || Object.keys(args).length > 0;\n // Trace identity travels on ExportedLog.traceId/spanId (the sink is\n // span-correlated); data stays reserved for the user payload. The mixin\n // still injects trace fields into the native pino record for stdout.\n ctx.getLogSink()?.[level](message, buildLogRecordData(hasPayload ? [args] : []));\n } catch {\n // Never let observability export break the primary logger\n }\n }\n\n debug(message: string, args: Record<string, any> = {}): void {\n this.logger.debug(args, message);\n this.#export('debug', message, args);\n }\n\n info(message: string, args: Record<string, any> = {}): void {\n this.logger.info(args, message);\n this.#export('info', message, args);\n }\n\n warn(message: string, args: Record<string, any> = {}): void {\n this.logger.warn(args, message);\n this.#export('warn', message, args);\n }\n\n error(message: string, args: Record<string, any> = {}): void {\n this.logger.error(args, message);\n this.#export('error', message, args);\n }\n\n override trackException(error: Error, metadata?: Record<string, unknown>): void {\n exportTrackedException(this.#adapterContextRef.current, error, metadata);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,aAAb,MAAa,mBAAwDA,oBAAAA,aAAa;CAChF;CAKA;CAEA,YAAY,UAA2C,CAAC,GAAG;EACzD,MAAM,OAAO;EAEb,MAAM,kBAAkB;EACxB,KAAKC,qBAAqB,gBAAgB,sBAAsB,CAAC;EAGjE,IAAI,gBAAgB,SAAS;GAC3B,KAAK,SAAS,gBAAgB;GAC9B;EACF;EAMA,MAAM,YAAY,QAAQ;EAC1B,MAAM,oBAAgD,a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from 'pino-pretty';
4
-
5
- // src/pino.ts
6
- var PinoLogger = class _PinoLogger extends MastraLogger {
7
- logger;
8
- constructor(options = {}) {
9
- super(options);
10
- const internalOptions = options;
11
- if (internalOptions._logger) {
12
- this.logger = internalOptions._logger;
13
- return;
14
- }
15
- const shouldPrettyPrint = options.prettyPrint ?? true;
16
- let prettyStream = void 0;
17
- if (!options.overrideDefaultTransports && shouldPrettyPrint) {
18
- prettyStream = pretty({
19
- colorize: true,
20
- levelFirst: true,
21
- ignore: "pid,hostname,component",
22
- colorizeObjects: true,
23
- translateTime: "SYS:standard",
24
- singleLine: false
25
- });
26
- }
27
- const transportsAry = [...this.getTransports().entries()];
28
- this.logger = pino(
29
- {
30
- name: options.name || "app",
31
- level: options.level || LogLevel.INFO,
32
- formatters: options.formatters,
33
- redact: options.redact,
34
- mixin: options.mixin,
35
- customLevels: options.customLevels,
36
- messageKey: options.messageKey ?? "msg"
37
- },
38
- options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? prettyStream : pino.multistream([
39
- ...transportsAry.map(([, transport]) => ({
40
- stream: transport,
41
- level: options.level || LogLevel.INFO
42
- })),
43
- ...prettyStream ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }] : []
44
- ])
45
- );
46
- }
47
- /**
48
- * Creates a child logger with additional bound context.
49
- * All logs from the child logger will include the bound context.
50
- *
51
- * @param bindings - Key-value pairs to include in all logs from this child logger
52
- * @returns A new PinoLogger instance with the bound context
53
- *
54
- * @example
55
- * ```typescript
56
- * const baseLogger = new PinoLogger({ name: 'MyApp' });
57
- *
58
- * // Create module-scoped logger
59
- * const serviceLogger = baseLogger.child({ module: 'UserService' });
60
- * serviceLogger.info('User created', { userId: '123' });
61
- * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }
62
- *
63
- * // Create request-scoped logger
64
- * const requestLogger = baseLogger.child({ requestId: req.id });
65
- * requestLogger.error('Request failed', { err: error });
66
- * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }
67
- * ```
68
- */
69
- child(bindings) {
70
- const childPino = this.logger.child(bindings);
71
- const childOptions = {
72
- name: this.name,
73
- level: this.level,
74
- transports: Object.fromEntries(this.transports),
75
- _logger: childPino
76
- };
77
- return new _PinoLogger(childOptions);
78
- }
79
- debug(message, args = {}) {
80
- this.logger.debug(args, message);
81
- }
82
- info(message, args = {}) {
83
- this.logger.info(args, message);
84
- }
85
- warn(message, args = {}) {
86
- this.logger.warn(args, message);
87
- }
88
- error(message, args = {}) {
89
- this.logger.error(args, message);
90
- }
1
+ import { LogLevel, MastraLogger, buildLogRecordData, exportTrackedException } from "@mastra/core/logger";
2
+ import pino from "pino";
3
+ import pretty from "pino-pretty";
4
+ //#region src/pino.ts
5
+ var PinoLogger = class PinoLogger extends MastraLogger {
6
+ logger;
7
+ #adapterContextRef;
8
+ constructor(options = {}) {
9
+ super(options);
10
+ const internalOptions = options;
11
+ this.#adapterContextRef = internalOptions._adapterContextRef ?? {};
12
+ if (internalOptions._logger) {
13
+ this.logger = internalOptions._logger;
14
+ return;
15
+ }
16
+ const userMixin = options.mixin;
17
+ const correlationMixin = (mergeObject, level, logger) => {
18
+ const userFields = userMixin ? userMixin(mergeObject, level, logger) : {};
19
+ const ctx = this.#adapterContextRef.current;
20
+ if (!ctx?.options.correlation) return userFields;
21
+ try {
22
+ return {
23
+ ...userFields,
24
+ ...ctx.resolveTraceFields() ?? {}
25
+ };
26
+ } catch {
27
+ return userFields;
28
+ }
29
+ };
30
+ const shouldPrettyPrint = options.prettyPrint ?? true;
31
+ let prettyStream = void 0;
32
+ if (!options.overrideDefaultTransports && shouldPrettyPrint) prettyStream = pretty({
33
+ colorize: true,
34
+ levelFirst: true,
35
+ ignore: "pid,hostname,component",
36
+ colorizeObjects: true,
37
+ translateTime: "SYS:standard",
38
+ singleLine: false
39
+ });
40
+ const transportsAry = [...this.getTransports().entries()];
41
+ this.logger = pino({
42
+ name: options.name || "app",
43
+ level: options.level || LogLevel.INFO,
44
+ formatters: options.formatters,
45
+ redact: options.redact,
46
+ mixin: correlationMixin,
47
+ customLevels: options.customLevels,
48
+ messageKey: options.messageKey ?? "msg"
49
+ }, options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? prettyStream : pino.multistream([...transportsAry.map(([, transport]) => ({
50
+ stream: transport,
51
+ level: options.level || LogLevel.INFO
52
+ })), ...prettyStream ? [{
53
+ stream: prettyStream,
54
+ level: options.level || LogLevel.INFO
55
+ }] : []]));
56
+ }
57
+ /**
58
+ * Creates a child logger with additional bound context.
59
+ * All logs from the child logger will include the bound context.
60
+ *
61
+ * @param bindings - Key-value pairs to include in all logs from this child logger
62
+ * @returns A new PinoLogger instance with the bound context
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const baseLogger = new PinoLogger({ name: 'MyApp' });
67
+ *
68
+ * // Create module-scoped logger
69
+ * const serviceLogger = baseLogger.child({ module: 'UserService' });
70
+ * serviceLogger.info('User created', { userId: '123' });
71
+ * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }
72
+ *
73
+ * // Create request-scoped logger
74
+ * const requestLogger = baseLogger.child({ requestId: req.id });
75
+ * requestLogger.error('Request failed', { err: error });
76
+ * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }
77
+ * ```
78
+ */
79
+ child(bindings) {
80
+ const childPino = this.logger.child(bindings);
81
+ const childOptions = {
82
+ name: this.name,
83
+ level: this.level,
84
+ transports: Object.fromEntries(this.transports),
85
+ _logger: childPino,
86
+ _adapterContextRef: this.#adapterContextRef
87
+ };
88
+ return new PinoLogger(childOptions);
89
+ }
90
+ /**
91
+ * Adapter hook (see `AdaptableLogger` in `@mastra/core/logger`): enables
92
+ * native trace correlation (trace_id/span_id merged into the pino record
93
+ * via mixin, for every destination) and observability export derived from
94
+ * the same record. Called by Mastra during setup.
95
+ */
96
+ __attachObservability(ctx) {
97
+ this.#adapterContextRef.current = ctx;
98
+ }
99
+ /**
100
+ * The adapter context lives on the ref cell shared by the whole
101
+ * root/child family, so re-attach detection (multi-Mastra warning) must
102
+ * key on that cell — attaching to a child re-targets the root too.
103
+ */
104
+ __observabilityAttachmentKey() {
105
+ return this.#adapterContextRef;
106
+ }
107
+ /**
108
+ * Export the record derived from the same native call to observability.
109
+ * Runs regardless of pino's level filter and never throws into the caller.
110
+ */
111
+ #export(level, message, args) {
112
+ const ctx = this.#adapterContextRef.current;
113
+ if (!ctx?.options.export) return;
114
+ try {
115
+ const hasPayload = args instanceof Error || Object.keys(args).length > 0;
116
+ ctx.getLogSink()?.[level](message, buildLogRecordData(hasPayload ? [args] : []));
117
+ } catch {}
118
+ }
119
+ debug(message, args = {}) {
120
+ this.logger.debug(args, message);
121
+ this.#export("debug", message, args);
122
+ }
123
+ info(message, args = {}) {
124
+ this.logger.info(args, message);
125
+ this.#export("info", message, args);
126
+ }
127
+ warn(message, args = {}) {
128
+ this.logger.warn(args, message);
129
+ this.#export("warn", message, args);
130
+ }
131
+ error(message, args = {}) {
132
+ this.logger.error(args, message);
133
+ this.#export("error", message, args);
134
+ }
135
+ trackException(error, metadata) {
136
+ exportTrackedException(this.#adapterContextRef.current, error, metadata);
137
+ }
91
138
  };
92
-
139
+ //#endregion
93
140
  export { PinoLogger };
94
- //# sourceMappingURL=index.js.map
141
+
95
142
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pino.ts"],"names":[],"mappings":";;;;;AAwCO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAwD,YAAA,CAAa;AAAA,EACtE,MAAA;AAAA,EAEV,WAAA,CAAY,OAAA,GAA2C,EAAC,EAAG;AACzD,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,MAAM,eAAA,GAAkB,OAAA;AAGxB,IAAA,IAAI,gBAAgB,OAAA,EAAS;AAC3B,MAAA,IAAA,CAAK,SAAS,eAAA,CAAgB,OAAA;AAC9B,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,iBAAA,GAAoB,QAAQ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Level, MastraLogger } from '@mastra/core/logger';\nimport pino from 'pino';\nimport pretty from 'pino-pretty';\n\ntype TransportMap = Record<string, LoggerTransport>;\n\nexport type { LogLevel } from '@mastra/core/logger';\n\nexport interface PinoLoggerOptions<CustomLevels extends string = never> {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n mixin?: pino.MixinFn<CustomLevels>;\n customLevels?: { [level in CustomLevels]: number };\n /**\n * When false, disables pino-pretty and outputs raw JSON.\n * Useful when sending logs to aggregators like Datadog,\n * Loki, or CloudWatch that expect single-line JSON per entry.\n * @default true\n */\n prettyPrint?: boolean;\n /**\n * Override the key used for the log message.\n * Defaults to Pino's built-in 'msg' key.\n * Set to 'message' for compatibility with Google Cloud Logging,\n * Elastic Common Schema (ECS), Datadog, and AWS CloudWatch.\n * @example 'message'\n */\n messageKey?: string;\n}\n\ninterface PinoLoggerInternalOptions<CustomLevels extends string = never> extends PinoLoggerOptions<CustomLevels> {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger<CustomLevels>;\n}\n\nexport class PinoLogger<CustomLevels extends string = never> extends MastraLogger {\n protected logger: pino.Logger<CustomLevels>;\n\n constructor(options: PinoLoggerOptions<CustomLevels> = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions<CustomLevels>;\n\n // If an existing pino logger is provided (for child loggers), use it directly\n if (internalOptions._logger) {\n this.logger = internalOptions._logger;\n return;\n }\n\n const shouldPrettyPrint = options.prettyPrint ?? true;\n let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports && shouldPrettyPrint) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname,component',\n colorizeObjects: true,\n translateTime: 'SYS:standard',\n singleLine: false,\n });\n }\n\n const transportsAry = [...this.getTransports().entries()];\n this.logger = pino(\n {\n name: options.name || 'app',\n level: options.level || LogLevel.INFO,\n formatters: options.formatters,\n redact: options.redact,\n mixin: options.mixin,\n customLevels: options.customLevels,\n messageKey: options.messageKey ?? 'msg',\n },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream // undefined when prettyPrint:false → pino native JSON\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n ...(prettyStream // only add prettyStream to multistream if it exists\n ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }]\n : []),\n ]),\n );\n }\n\n /**\n * Creates a child logger with additional bound context.\n * All logs from the child logger will include the bound context.\n *\n * @param bindings - Key-value pairs to include in all logs from this child logger\n * @returns A new PinoLogger instance with the bound context\n *\n * @example\n * ```typescript\n * const baseLogger = new PinoLogger({ name: 'MyApp' });\n *\n * // Create module-scoped logger\n * const serviceLogger = baseLogger.child({ module: 'UserService' });\n * serviceLogger.info('User created', { userId: '123' });\n * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }\n *\n * // Create request-scoped logger\n * const requestLogger = baseLogger.child({ requestId: req.id });\n * requestLogger.error('Request failed', { err: error });\n * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }\n * ```\n */\n child(bindings: Record<string, unknown>): PinoLogger<CustomLevels> {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions<CustomLevels> = {\n name: this.name,\n level: this.level,\n transports: Object.fromEntries(this.transports),\n _logger: childPino,\n };\n return new PinoLogger(childOptions);\n }\n\n debug(message: string, args: Record<string, any> = {}): void {\n this.logger.debug(args, message);\n }\n\n info(message: string, args: Record<string, any> = {}): void {\n this.logger.info(args, message);\n }\n\n warn(message: string, args: Record<string, any> = {}): void {\n this.logger.warn(args, message);\n }\n\n error(message: string, args: Record<string, any> = {}): void {\n this.logger.error(args, message);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","names":["#adapterContextRef","#export"],"sources":["../src/pino.ts"],"sourcesContent":["import type { LoggerTransport, LoggerAdapterContext } from '@mastra/core/logger';\nimport { LogLevel, MastraLogger, buildLogRecordData, exportTrackedException } from '@mastra/core/logger';\nimport pino from 'pino';\nimport pretty from 'pino-pretty';\n\ntype TransportMap = Record<string, LoggerTransport>;\n\nexport type { LogLevel } from '@mastra/core/logger';\n\nexport interface PinoLoggerOptions<CustomLevels extends string = never> {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n mixin?: pino.MixinFn<CustomLevels>;\n customLevels?: { [level in CustomLevels]: number };\n /**\n * When false, disables pino-pretty and outputs raw JSON.\n * Useful when sending logs to aggregators like Datadog,\n * Loki, or CloudWatch that expect single-line JSON per entry.\n * @default true\n */\n prettyPrint?: boolean;\n /**\n * Override the key used for the log message.\n * Defaults to Pino's built-in 'msg' key.\n * Set to 'message' for compatibility with Google Cloud Logging,\n * Elastic Common Schema (ECS), Datadog, and AWS CloudWatch.\n * @example 'message'\n */\n messageKey?: string;\n}\n\ninterface PinoLoggerInternalOptions<CustomLevels extends string = never> extends PinoLoggerOptions<CustomLevels> {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger<CustomLevels>;\n /** @internal Shared adapter-context ref so root and children correlate together */\n _adapterContextRef?: { current?: LoggerAdapterContext };\n}\n\nexport class PinoLogger<CustomLevels extends string = never> extends MastraLogger {\n protected logger: pino.Logger<CustomLevels>;\n // Mutable ref shared with child loggers: the root's mixin (which children's\n // pino instances inherit) reads through this ref, so attaching observability\n // to a child (e.g. `new Mastra({ logger: base.child({...}) })`) correlates\n // the records it actually logs through.\n #adapterContextRef: { current?: LoggerAdapterContext };\n\n constructor(options: PinoLoggerOptions<CustomLevels> = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions<CustomLevels>;\n this.#adapterContextRef = internalOptions._adapterContextRef ?? {};\n\n // If an existing pino logger is provided (for child loggers), use it directly\n if (internalOptions._logger) {\n this.logger = internalOptions._logger;\n return;\n }\n\n // Compose the user mixin with trace correlation. Pino mixins run\n // synchronously on every log call, so the trace fields land in the\n // native record before serialization — for ALL destinations (stdout,\n // transports, files). Trace fields win on key conflicts.\n const userMixin = options.mixin;\n const correlationMixin: pino.MixinFn<CustomLevels> = (mergeObject, level, logger) => {\n const userFields = userMixin ? userMixin(mergeObject, level, logger) : {};\n const ctx = this.#adapterContextRef.current;\n if (!ctx?.options.correlation) return userFields;\n try {\n return { ...userFields, ...(ctx.resolveTraceFields() ?? {}) };\n } catch {\n return userFields;\n }\n };\n\n const shouldPrettyPrint = options.prettyPrint ?? true;\n let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports && shouldPrettyPrint) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname,component',\n colorizeObjects: true,\n translateTime: 'SYS:standard',\n singleLine: false,\n });\n }\n\n const transportsAry = [...this.getTransports().entries()];\n this.logger = pino(\n {\n name: options.name || 'app',\n level: options.level || LogLevel.INFO,\n formatters: options.formatters,\n redact: options.redact,\n mixin: correlationMixin,\n customLevels: options.customLevels,\n messageKey: options.messageKey ?? 'msg',\n },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream // undefined when prettyPrint:false → pino native JSON\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n ...(prettyStream // only add prettyStream to multistream if it exists\n ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }]\n : []),\n ]),\n );\n }\n\n /**\n * Creates a child logger with additional bound context.\n * All logs from the child logger will include the bound context.\n *\n * @param bindings - Key-value pairs to include in all logs from this child logger\n * @returns A new PinoLogger instance with the bound context\n *\n * @example\n * ```typescript\n * const baseLogger = new PinoLogger({ name: 'MyApp' });\n *\n * // Create module-scoped logger\n * const serviceLogger = baseLogger.child({ module: 'UserService' });\n * serviceLogger.info('User created', { userId: '123' });\n * // Output includes: { module: 'UserService', userId: '123', msg: 'User created' }\n *\n * // Create request-scoped logger\n * const requestLogger = baseLogger.child({ requestId: req.id });\n * requestLogger.error('Request failed', { err: error });\n * // Output includes: { requestId: 'abc', msg: 'Request failed', err: {...} }\n * ```\n */\n child(bindings: Record<string, unknown>): PinoLogger<CustomLevels> {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions<CustomLevels> = {\n name: this.name,\n level: this.level,\n transports: Object.fromEntries(this.transports),\n _logger: childPino,\n _adapterContextRef: this.#adapterContextRef,\n };\n return new PinoLogger(childOptions);\n }\n\n /**\n * Adapter hook (see `AdaptableLogger` in `@mastra/core/logger`): enables\n * native trace correlation (trace_id/span_id merged into the pino record\n * via mixin, for every destination) and observability export derived from\n * the same record. Called by Mastra during setup.\n */\n __attachObservability(ctx: LoggerAdapterContext): void {\n // Shared ref: attaching to a child also enables correlation on the root\n // mixin the child's records flow through (and vice versa).\n this.#adapterContextRef.current = ctx;\n }\n\n /**\n * The adapter context lives on the ref cell shared by the whole\n * root/child family, so re-attach detection (multi-Mastra warning) must\n * key on that cell — attaching to a child re-targets the root too.\n */\n __observabilityAttachmentKey(): object {\n return this.#adapterContextRef;\n }\n\n /**\n * Export the record derived from the same native call to observability.\n * Runs regardless of pino's level filter and never throws into the caller.\n */\n #export(level: 'debug' | 'info' | 'warn' | 'error', message: string, args: Record<string, any>): void {\n const ctx = this.#adapterContextRef.current;\n if (!ctx?.options.export) return;\n try {\n // An Error passed as the args value often has no enumerable keys but\n // must still be exported (serialized by buildLogRecordData).\n const hasPayload = args instanceof Error || Object.keys(args).length > 0;\n // Trace identity travels on ExportedLog.traceId/spanId (the sink is\n // span-correlated); data stays reserved for the user payload. The mixin\n // still injects trace fields into the native pino record for stdout.\n ctx.getLogSink()?.[level](message, buildLogRecordData(hasPayload ? [args] : []));\n } catch {\n // Never let observability export break the primary logger\n }\n }\n\n debug(message: string, args: Record<string, any> = {}): void {\n this.logger.debug(args, message);\n this.#export('debug', message, args);\n }\n\n info(message: string, args: Record<string, any> = {}): void {\n this.logger.info(args, message);\n this.#export('info', message, args);\n }\n\n warn(message: string, args: Record<string, any> = {}): void {\n this.logger.warn(args, message);\n this.#export('warn', message, args);\n }\n\n error(message: string, args: Record<string, any> = {}): void {\n this.logger.error(args, message);\n this.#export('error', message, args);\n }\n\n override trackException(error: Error, metadata?: Record<string, unknown>): void {\n exportTrackedException(this.#adapterContextRef.current, error, metadata);\n }\n}\n"],"mappings":";;;;AA0CA,IAAa,aAAb,MAAa,mBAAwD,aAAa;CAChF;CAKA;CAEA,YAAY,UAA2C,CAAC,GAAG;EACzD,MAAM,OAAO;EAEb,MAAM,kBAAkB;EACxB,KAAKA,qBAAqB,gBAAgB,sBAAsB,CAAC;EAGjE,IAAI,gBAAgB,SAAS;GAC3B,KAAK,SAAS,gBAAgB;GAC9B;EACF;EAMA,MAAM,YAAY,QAAQ;EAC1B,MAAM,oBAAgD,aAAa,OAAO,WAAW;GACnF,MAAM,aAAa,YAAY,UAAU,aAAa,OAAO,MAAM,IAAI,CAAC;GACxE,MAAM,MAAM,KAAKA,mBAAmB;GACpC,IAAI,CAAC,KAAK,QAAQ,aAAa,OAAO;GACtC,IAAI;IACF,OAAO;KAAE,GAAG;KAAY,GAAI,IAAI,mBAAmB,KAAK,CAAC;IAAG;GAC9D,QAAQ;IACN,OAAO;GACT;EACF;EAEA,MAAM,oBAAoB,QAAQ,eAAe;EACjD,IAAI,eAAsD,KAAA;EAC1D,IAAI,CAAC,QAAQ,6BAA6B,mBACxC,eAAe,OAAO;GACpB,UAAU;GACV,YAAY;GACZ,QAAQ;GACR,iBAAiB;GACjB,eAAe;GACf,YAAY;EACd,CAAC;EAGH,MAAM,gBAAgB,CAAC,GAAG,KAAK,cAAc,CAAC,CAAC,QAAQ,CAAC;EACxD,KAAK,SAAS,KACZ;GACE,MAAM,QAAQ,QAAQ;GACtB,OAAO,QAAQ,SAAS,SAAS;GACjC,YAAY,QAAQ;GACp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O;EAC9B,KAAKA,QAAQ,QAAQ,SAAS,IAAI;CACpC;CAEA,KAAK,SAAiB,OAA4B,CAAC,GAAS;EAC1D,KAAK,OAAO,KAAK,MAAM,OAAO;EAC9B,KAAKA,QAAQ,QAAQ,SAAS,IAAI;CACpC;CAEA,MAAM,SAAiB,OAA4B,CAAC,GAAS;EAC3D,KAAK,OAAO,MAAM,MAAM,OAAO;EAC/B,KAAKA,QAAQ,SAAS,SAAS,IAAI;CACrC;CAEA,eAAwB,OAAc,UAA0C;EAC9E,uBAAuB,KAAKD,mBAAmB,SAAS,OAAO,QAAQ;CACzE;AACF"}
package/dist/pino.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { LoggerTransport } from '@mastra/core/logger';
1
+ import type { LoggerTransport, LoggerAdapterContext } from '@mastra/core/logger';
2
2
  import { LogLevel, MastraLogger } from '@mastra/core/logger';
3
3
  import pino from 'pino';
4
4
  type TransportMap = Record<string, LoggerTransport>;
@@ -31,6 +31,7 @@ export interface PinoLoggerOptions<CustomLevels extends string = never> {
31
31
  messageKey?: string;
32
32
  }
33
33
  export declare class PinoLogger<CustomLevels extends string = never> extends MastraLogger {
34
+ #private;
34
35
  protected logger: pino.Logger<CustomLevels>;
35
36
  constructor(options?: PinoLoggerOptions<CustomLevels>);
36
37
  /**
@@ -56,9 +57,23 @@ export declare class PinoLogger<CustomLevels extends string = never> extends Mas
56
57
  * ```
57
58
  */
58
59
  child(bindings: Record<string, unknown>): PinoLogger<CustomLevels>;
60
+ /**
61
+ * Adapter hook (see `AdaptableLogger` in `@mastra/core/logger`): enables
62
+ * native trace correlation (trace_id/span_id merged into the pino record
63
+ * via mixin, for every destination) and observability export derived from
64
+ * the same record. Called by Mastra during setup.
65
+ */
66
+ __attachObservability(ctx: LoggerAdapterContext): void;
67
+ /**
68
+ * The adapter context lives on the ref cell shared by the whole
69
+ * root/child family, so re-attach detection (multi-Mastra warning) must
70
+ * key on that cell — attaching to a child re-targets the root too.
71
+ */
72
+ __observabilityAttachmentKey(): object;
59
73
  debug(message: string, args?: Record<string, any>): void;
60
74
  info(message: string, args?: Record<string, any>): void;
61
75
  warn(message: string, args?: Record<string, any>): void;
62
76
  error(message: string, args?: Record<string, any>): void;
77
+ trackException(error: Error, metadata?: Record<string, unknown>): void;
63
78
  }
64
79
  //# sourceMappingURL=pino.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../src/pino.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEpD,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,iBAAiB,CAAC,YAAY,SAAS,MAAM,GAAG,KAAK;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,UAAU,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACnC,YAAY,CAAC,EAAE;SAAG,KAAK,IAAI,YAAY,GAAG,MAAM;KAAE,CAAC;IACnD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAOD,qBAAa,UAAU,CAAC,YAAY,SAAS,MAAM,GAAG,KAAK,CAAE,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