@mastra/loggers 1.0.2 → 1.0.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @mastra/loggers
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed: PinoLogger now supports JSON output for log aggregators ([#14306](https://github.com/mastra-ai/mastra/pull/14306))
8
+
9
+ Previously, PinoLogger always used pino-pretty which produced multiline
10
+ colored output, breaking log aggregators like Datadog, Loki, and CloudWatch.
11
+ A new prettyPrint option allows switching to single-line JSON output.
12
+
13
+ - Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`b77aa19`](https://github.com/mastra-ai/mastra/commit/b77aa1981361c021f2c881bee8f0c703687f00da), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8b4ce84`](https://github.com/mastra-ai/mastra/commit/8b4ce84aed0808b9805cc4fd7147c1f8a2ef7a36), [`8d4cfe6`](https://github.com/mastra-ai/mastra/commit/8d4cfe6b9a7157d3876206227ec9f04cde6dbc4a), [`dd6ca1c`](https://github.com/mastra-ai/mastra/commit/dd6ca1cdea3b8b6182f4cf61df41070ba0cc0deb), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a), [`4cb4edf`](https://github.com/mastra-ai/mastra/commit/4cb4edf3c909d197ec356c1790d13270514ffef6), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a)]:
14
+ - @mastra/core@1.14.0
15
+
16
+ ## 1.0.3-alpha.0
17
+
18
+ ### Patch Changes
19
+
20
+ - Fixed: PinoLogger now supports JSON output for log aggregators ([#14306](https://github.com/mastra-ai/mastra/pull/14306))
21
+
22
+ Previously, PinoLogger always used pino-pretty which produced multiline
23
+ colored output, breaking log aggregators like Datadog, Loki, and CloudWatch.
24
+ A new prettyPrint option allows switching to single-line JSON output.
25
+
26
+ - Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1)]:
27
+ - @mastra/core@1.13.3-alpha.0
28
+
3
29
  ## 1.0.2
4
30
 
5
31
  ### Patch Changes
package/LICENSE.md CHANGED
@@ -1,3 +1,18 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
1
16
  # Apache License 2.0
2
17
 
3
18
  Copyright (c) 2025 Kepler Software, Inc.
@@ -3,7 +3,7 @@ name: mastra-loggers
3
3
  description: Documentation for @mastra/loggers. Use when working with @mastra/loggers APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/loggers"
6
- version: "1.0.2"
6
+ version: "1.0.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -17,11 +17,11 @@ Read the individual reference documents for detailed explanations and code examp
17
17
  ### Docs
18
18
 
19
19
  - [Logging](references/docs-observability-logging.md) - Learn how to use logging in Mastra to monitor execution, capture application behavior, and improve the accuracy of AI applications.
20
- - [Observability Overview](references/docs-observability-overview.md) - Monitor and debug applications with Mastra's Observability features.
20
+ - [Observability overview](references/docs-observability-overview.md) - Monitor and debug applications with Mastra's Observability features.
21
21
 
22
22
  ### Reference
23
23
 
24
- - [Reference: Mastra Class](references/reference-core-mastra-class.md) - Documentation for the `Mastra` class in Mastra, the core entry point for managing agents, workflows, MCP servers, and server endpoints.
24
+ - [Reference: Mastra class](references/reference-core-mastra-class.md) - Documentation for the `Mastra` class in Mastra, the core entry point for managing agents, workflows, MCP servers, and server endpoints.
25
25
  - [Reference: PinoLogger](references/reference-logging-pino-logger.md) - Documentation for PinoLogger, which provides methods to record events at various severity levels.
26
26
 
27
27
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.2",
2
+ "version": "1.0.3",
3
3
  "package": "@mastra/loggers",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -4,20 +4,20 @@ Mastra's logging system captures function execution, input data, and output resp
4
4
 
5
5
  When deploying to Mastra Cloud, logs are shown on the [Logs](https://mastra.ai/docs/mastra-cloud/observability) page. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.
6
6
 
7
- ## Configuring logs with PinoLogger
7
+ ## Configuring logs with `PinoLogger`
8
8
 
9
9
  When [initializing a new Mastra project](https://mastra.ai/guides/getting-started/quickstart) using the CLI, `PinoLogger` is included by default.
10
10
 
11
11
  ```typescript
12
- import { Mastra } from "@mastra/core/mastra";
13
- import { PinoLogger } from "@mastra/loggers";
12
+ import { Mastra } from '@mastra/core/mastra'
13
+ import { PinoLogger } from '@mastra/loggers'
14
14
 
15
15
  export const mastra = new Mastra({
16
16
  logger: new PinoLogger({
17
- name: "Mastra",
18
- level: "info",
17
+ name: 'Mastra',
18
+ level: 'info',
19
19
  }),
20
- });
20
+ })
21
21
  ```
22
22
 
23
23
  > **Info:** Visit [PinoLogger](https://mastra.ai/reference/logging/pino-logger) for all available configuration options.
@@ -55,19 +55,19 @@ export const testWorkflow = createWorkflow({...})
55
55
  Similarly, tools have access to the logger instance via the `mastra` parameter. Use this to log tool specific activity during execution.
56
56
 
57
57
  ```typescript
58
- import { createTool } from "@mastra/core/tools";
59
- import { z } from "zod";
58
+ import { createTool } from '@mastra/core/tools'
59
+ import { z } from 'zod'
60
60
 
61
61
  export const testTool = createTool({
62
62
  execute: async (inputData, context) => {
63
- const logger = context?.mastra.getLogger();
64
- logger?.info("tool info log");
63
+ const logger = context?.mastra.getLogger()
64
+ logger?.info('tool info log')
65
65
 
66
66
  return {
67
- output: "",
68
- };
67
+ output: '',
68
+ }
69
69
  },
70
- });
70
+ })
71
71
  ```
72
72
 
73
73
  ### Logging with additional data
@@ -1,8 +1,8 @@
1
- # Observability Overview
1
+ # Observability overview
2
2
 
3
3
  Mastra provides observability features for AI applications. Monitor LLM operations, trace agent decisions, and debug complex workflows with tools that understand AI-specific patterns.
4
4
 
5
- ## Key Features
5
+ ## Key features
6
6
 
7
7
  ### Tracing
8
8
 
@@ -13,37 +13,37 @@ Specialized tracing for AI operations that captures:
13
13
  - **Workflow steps**: Branching logic, parallel execution, and step outputs
14
14
  - **Automatic instrumentation**: Tracing with decorators
15
15
 
16
- ## Storage Requirements
16
+ ## Storage requirements
17
17
 
18
18
  The `DefaultExporter` persists traces to your configured storage backend. Not all storage providers support observability—for the full list, see [Storage Provider Support](https://mastra.ai/docs/observability/tracing/exporters/default).
19
19
 
20
20
  For production environments with high traffic, we recommend using **ClickHouse** for the observability domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](https://mastra.ai/docs/observability/tracing/exporters/default) for details.
21
21
 
22
- ## Quick Start
22
+ ## Quick start
23
23
 
24
24
  Configure Observability in your Mastra instance:
25
25
 
26
26
  ```typescript
27
- import { Mastra } from "@mastra/core";
28
- import { PinoLogger } from "@mastra/loggers";
29
- import { LibSQLStore } from "@mastra/libsql";
27
+ import { Mastra } from '@mastra/core'
28
+ import { PinoLogger } from '@mastra/loggers'
29
+ import { LibSQLStore } from '@mastra/libsql'
30
30
  import {
31
31
  Observability,
32
32
  DefaultExporter,
33
33
  CloudExporter,
34
34
  SensitiveDataFilter,
35
- } from "@mastra/observability";
35
+ } from '@mastra/observability'
36
36
 
37
37
  export const mastra = new Mastra({
38
38
  logger: new PinoLogger(),
39
39
  storage: new LibSQLStore({
40
40
  id: 'mastra-storage',
41
- url: "file:./mastra.db", // Storage is required for tracing
41
+ url: 'file:./mastra.db', // Storage is required for tracing
42
42
  }),
43
43
  observability: new Observability({
44
44
  configs: {
45
45
  default: {
46
- serviceName: "mastra",
46
+ serviceName: 'mastra',
47
47
  exporters: [
48
48
  new DefaultExporter(), // Persists traces to storage for Mastra Studio
49
49
  new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
@@ -54,7 +54,7 @@ export const mastra = new Mastra({
54
54
  },
55
55
  },
56
56
  }),
57
- });
57
+ })
58
58
  ```
59
59
 
60
60
  > **Serverless environments:** The `file:./mastra.db` storage URL uses the local filesystem, which doesn't work in serverless environments like Vercel, AWS Lambda, or Cloudflare Workers. For serverless deployments, use external storage. See the [Vercel deployment guide](https://mastra.ai/guides/deployment/vercel) for a complete example.
@@ -63,7 +63,7 @@ With this basic setup, you will see Traces and Logs in both Studio and in Mastra
63
63
 
64
64
  We also support various external tracing providers like MLflow, Langfuse, Braintrust, and any OpenTelemetry-compatible platform (Datadog, New Relic, SigNoz, etc.). See more about this in the [Tracing](https://mastra.ai/docs/observability/tracing/overview) documentation.
65
65
 
66
- ## What's Next?
66
+ ## What's next?
67
67
 
68
68
  - **[Set up Tracing](https://mastra.ai/docs/observability/tracing/overview)**: Configure tracing for your application
69
69
  - **[Configure Logging](https://mastra.ai/docs/observability/logging)**: Add structured logging
@@ -1,4 +1,4 @@
1
- # Mastra Class
1
+ # Mastra class
2
2
 
3
3
  The `Mastra` class is the central orchestrator in any Mastra application, managing agents, workflows, storage, logging, observability, and more. Typically, you create a single instance of `Mastra` to coordinate your application.
4
4
 
@@ -7,60 +7,60 @@ Think of `Mastra` as a top-level registry where you register agents, workflows,
7
7
  ## Usage example
8
8
 
9
9
  ```typescript
10
- import { Mastra } from "@mastra/core";
11
- import { PinoLogger } from "@mastra/loggers";
12
- import { LibSQLStore } from "@mastra/libsql";
13
- import { weatherWorkflow } from "./workflows/weather-workflow";
14
- import { weatherAgent } from "./agents/weather-agent";
10
+ import { Mastra } from '@mastra/core'
11
+ import { PinoLogger } from '@mastra/loggers'
12
+ import { LibSQLStore } from '@mastra/libsql'
13
+ import { weatherWorkflow } from './workflows/weather-workflow'
14
+ import { weatherAgent } from './agents/weather-agent'
15
15
 
16
16
  export const mastra = new Mastra({
17
17
  workflows: { weatherWorkflow },
18
18
  agents: { weatherAgent },
19
19
  storage: new LibSQLStore({
20
20
  id: 'mastra-storage',
21
- url: ":memory:",
21
+ url: ':memory:',
22
22
  }),
23
23
  logger: new PinoLogger({
24
- name: "Mastra",
25
- level: "info",
24
+ name: 'Mastra',
25
+ level: 'info',
26
26
  }),
27
- });
27
+ })
28
28
  ```
29
29
 
30
30
  ## Constructor parameters
31
31
 
32
32
  Visit the [Configuration reference](https://mastra.ai/reference/configuration) for detailed documentation on all available configuration options.
33
33
 
34
- **agents?:** (`Record<string, Agent>`): Agent instances to register, keyed by name (Default: `{}`)
34
+ **agents** (`Record<string, Agent>`): Agent instances to register, keyed by name (Default: `{}`)
35
35
 
36
- **tools?:** (`Record<string, ToolApi>`): Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function. (Default: `{}`)
36
+ **tools** (`Record<string, ToolApi>`): Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function. (Default: `{}`)
37
37
 
38
- **storage?:** (`MastraCompositeStore`): Storage engine instance for persisting data
38
+ **storage** (`MastraCompositeStore`): Storage engine instance for persisting data
39
39
 
40
- **vectors?:** (`Record<string, MastraVector>`): Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)
40
+ **vectors** (`Record<string, MastraVector>`): Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)
41
41
 
42
- **logger?:** (`Logger`): Logger instance created with new PinoLogger() (Default: `Console logger with INFO level`)
42
+ **logger** (`Logger`): Logger instance created with new PinoLogger() (Default: `Console logger with INFO level`)
43
43
 
44
- **idGenerator?:** (`() => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers.
44
+ **idGenerator** (`(context?: IdGeneratorContext) => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers. Receives optional context such as idType, source, entityId, and threadId to support context-aware ID formats.
45
45
 
46
- **workflows?:** (`Record<string, Workflow>`): Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance. (Default: `{}`)
46
+ **workflows** (`Record<string, Workflow>`): Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance. (Default: `{}`)
47
47
 
48
- **tts?:** (`Record<string, MastraVoice>`): Text-to-speech providers for voice synthesis
48
+ **tts** (`Record<string, MastraVoice>`): Text-to-speech providers for voice synthesis
49
49
 
50
- **observability?:** (`ObservabilityEntrypoint`): Observability configuration for tracing and monitoring
50
+ **observability** (`ObservabilityEntrypoint`): Observability configuration for tracing and monitoring
51
51
 
52
- **deployer?:** (`MastraDeployer`): An instance of a MastraDeployer for managing deployments.
52
+ **deployer** (`MastraDeployer`): An instance of a MastraDeployer for managing deployments.
53
53
 
54
- **server?:** (`ServerConfig`): Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.
54
+ **server** (`ServerConfig`): Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.
55
55
 
56
- **mcpServers?:** (`Record<string, MCPServerBase>`): An object where keys are registry keys (used for getMCPServer()) and values are instances of MCPServer or classes extending MCPServerBase. Each MCPServer must have an id property. Servers can be retrieved by registry key using getMCPServer() or by their intrinsic id using getMCPServerById().
56
+ **mcpServers** (`Record<string, MCPServerBase>`): An object where keys are registry keys (used for getMCPServer()) and values are instances of MCPServer or classes extending MCPServerBase. Each MCPServer must have an id property. Servers can be retrieved by registry key using getMCPServer() or by their intrinsic id using getMCPServerById().
57
57
 
58
- **bundler?:** (`BundlerConfig`): Configuration for the asset bundler with options for externals, sourcemap, and transpilePackages.
58
+ **bundler** (`BundlerConfig`): Configuration for the asset bundler with options for externals, sourcemap, transpilePackages, and dynamicPackages. (Default: `{ externals: [], sourcemap: false, transpilePackages: [], dynamicPackages: [] }`)
59
59
 
60
- **scorers?:** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs (Default: `{}`)
60
+ **scorers** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs (Default: `{}`)
61
61
 
62
- **processors?:** (`Record<string, Processor>`): Input/output processors for transforming agent inputs and outputs (Default: `{}`)
62
+ **processors** (`Record<string, Processor>`): Input/output processors for transforming agent inputs and outputs (Default: `{}`)
63
63
 
64
- **gateways?:** (`Record<string, MastraModelGateway>`): Custom model gateways to register for accessing AI models through alternative providers or private deployments. Structured as a key-value pair, with keys being the registry key (used for getGateway()) and values being gateway instances. (Default: `{}`)
64
+ **gateways** (`Record<string, MastraModelGateway>`): Custom model gateways to register for accessing AI models through alternative providers or private deployments. Structured as a key-value pair, with keys being the registry key (used for getGateway()) and values being gateway instances. (Default: `{}`)
65
65
 
66
- **memory?:** (`Record<string, MastraMemory>`): Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances. (Default: `{}`)
66
+ **memory** (`Record<string, MastraMemory>`): Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances. (Default: `{}`)
@@ -7,51 +7,51 @@ When deploying to Mastra Cloud, logs are displayed on the [Logs](https://mastra.
7
7
  ## Usage example
8
8
 
9
9
  ```typescript
10
- import { Mastra } from "@mastra/core";
11
- import { PinoLogger } from "@mastra/loggers";
10
+ import { Mastra } from '@mastra/core'
11
+ import { PinoLogger } from '@mastra/loggers'
12
12
 
13
13
  export const mastra = new Mastra({
14
14
  logger: new PinoLogger({
15
- name: "Mastra",
16
- level: "info",
15
+ name: 'Mastra',
16
+ level: 'info',
17
17
  }),
18
- });
18
+ })
19
19
  ```
20
20
 
21
21
  ## Parameters
22
22
 
23
- **name:** (`string`): A label used to group and identify logs from this logger.
23
+ **name** (`string`): A label used to group and identify logs from this logger.
24
24
 
25
- **level:** (`"debug" | "info" | "warn" | "error"`): Sets the minimum log level. Messages below this level are ignored.
25
+ **level** (`"debug" | "info" | "warn" | "error"`): Sets the minimum log level. Messages below this level are ignored.
26
26
 
27
- **transports:** (`Record<string, LoggerTransport>`): A map of transport instances used to persist logs.
27
+ **transports** (`Record<string, LoggerTransport>`): A map of transport instances used to persist logs.
28
28
 
29
- **overrideDefaultTransports?:** (`boolean`): If true, disables the default console transport.
29
+ **overrideDefaultTransports** (`boolean`): If true, disables the default console transport.
30
30
 
31
- **formatters?:** (`pino.LoggerOptions['formatters']`): Custom Pino formatters for log serialization.
31
+ **formatters** (`pino.LoggerOptions['formatters']`): Custom Pino formatters for log serialization.
32
32
 
33
33
  ## File transport (structured logs)
34
34
 
35
35
  Writes structured logs to a file using the `FileTransport`. The logger accepts a plain message as the first argument and structured metadata as the second argument. These are internally converted to a `BaseLogMessage` and persisted to the configured file path.
36
36
 
37
37
  ```typescript
38
- import { FileTransport } from "@mastra/loggers/file";
39
- import { PinoLogger } from "@mastra/loggers/pino";
38
+ import { FileTransport } from '@mastra/loggers/file'
39
+ import { PinoLogger } from '@mastra/loggers/pino'
40
40
 
41
41
  export const fileLogger = new PinoLogger({
42
- name: "Mastra",
43
- transports: { file: new FileTransport({ path: "test-dir/test.log" }) },
44
- level: "warn",
45
- });
42
+ name: 'Mastra',
43
+ transports: { file: new FileTransport({ path: 'test-dir/test.log' }) },
44
+ level: 'warn',
45
+ })
46
46
  ```
47
47
 
48
48
  ### File transport usage
49
49
 
50
50
  ```typescript
51
- fileLogger.warn("Low disk space", {
52
- destinationPath: "system",
53
- type: "WORKFLOW",
54
- });
51
+ fileLogger.warn('Low disk space', {
52
+ destinationPath: 'system',
53
+ type: 'WORKFLOW',
54
+ })
55
55
  ```
56
56
 
57
57
  ## Upstash transport (remote log drain)
@@ -59,30 +59,30 @@ fileLogger.warn("Low disk space", {
59
59
  Streams structured logs to a remote Redis list using the `UpstashTransport`. The logger accepts a string message and a structured metadata object. This enables centralized logging for distributed environments, supporting filtering by `destinationPath`, `type`, and `runId`.
60
60
 
61
61
  ```typescript
62
- import { UpstashTransport } from "@mastra/loggers/upstash";
63
- import { PinoLogger } from "@mastra/loggers/pino";
62
+ import { UpstashTransport } from '@mastra/loggers/upstash'
63
+ import { PinoLogger } from '@mastra/loggers/pino'
64
64
 
65
65
  export const upstashLogger = new PinoLogger({
66
- name: "Mastra",
66
+ name: 'Mastra',
67
67
  transports: {
68
68
  upstash: new UpstashTransport({
69
- listName: "production-logs",
69
+ listName: 'production-logs',
70
70
  upstashUrl: process.env.UPSTASH_URL!,
71
71
  upstashToken: process.env.UPSTASH_TOKEN!,
72
72
  }),
73
73
  },
74
- level: "info",
75
- });
74
+ level: 'info',
75
+ })
76
76
  ```
77
77
 
78
78
  ### Upstash transport usage
79
79
 
80
80
  ```typescript
81
- upstashLogger.info("User signed in", {
82
- destinationPath: "auth",
83
- type: "AGENT",
84
- runId: "run_123",
85
- });
81
+ upstashLogger.info('User signed in', {
82
+ destinationPath: 'auth',
83
+ type: 'AGENT',
84
+ runId: 'run_123',
85
+ })
86
86
  ```
87
87
 
88
88
  ## Custom transport
@@ -94,24 +94,24 @@ You can create custom transports using the `createCustomTransport` utility to in
94
94
  Creates a custom transport using `createCustomTransport` and integrates it with a third-party logging stream such as `pino-sentry-transport`. This allows forwarding logs to an external system like Sentry for advanced monitoring and observability.
95
95
 
96
96
  ```typescript
97
- import { createCustomTransport } from "@mastra/core/loggers";
98
- import { PinoLogger } from "@mastra/loggers/pino";
99
- import pinoSentry from "pino-sentry-transport";
97
+ import { createCustomTransport } from '@mastra/core/loggers'
98
+ import { PinoLogger } from '@mastra/loggers/pino'
99
+ import pinoSentry from 'pino-sentry-transport'
100
100
 
101
101
  const sentryStream = await pinoSentry({
102
102
  sentry: {
103
- dsn: "YOUR_SENTRY_DSN",
103
+ dsn: 'YOUR_SENTRY_DSN',
104
104
  _experiments: {
105
105
  enableLogs: true,
106
106
  },
107
107
  },
108
- });
108
+ })
109
109
 
110
- const customTransport = createCustomTransport(sentryStream);
110
+ const customTransport = createCustomTransport(sentryStream)
111
111
 
112
112
  export const sentryLogger = new PinoLogger({
113
- name: "Mastra",
114
- level: "info",
113
+ name: 'Mastra',
114
+ level: 'info',
115
115
  transports: { sentry: customTransport },
116
- });
116
+ })
117
117
  ```
package/dist/index.cjs CHANGED
@@ -19,8 +19,9 @@ var PinoLogger = class _PinoLogger extends logger.MastraLogger {
19
19
  this.logger = internalOptions._logger;
20
20
  return;
21
21
  }
22
+ const shouldPrettyPrint = options.prettyPrint ?? true;
22
23
  let prettyStream = void 0;
23
- if (!options.overrideDefaultTransports) {
24
+ if (!options.overrideDefaultTransports && shouldPrettyPrint) {
24
25
  prettyStream = pretty__default.default({
25
26
  colorize: true,
26
27
  levelFirst: true,
@@ -43,10 +44,7 @@ var PinoLogger = class _PinoLogger extends logger.MastraLogger {
43
44
  stream: transport,
44
45
  level: options.level || logger.LogLevel.INFO
45
46
  })),
46
- {
47
- stream: prettyStream,
48
- level: options.level || logger.LogLevel.INFO
49
- }
47
+ ...prettyStream ? [{ stream: prettyStream, level: options.level || logger.LogLevel.INFO }] : []
50
48
  ])
51
49
  );
52
50
  }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,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 {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n}\n\ninterface PinoLoggerInternalOptions extends PinoLoggerOptions {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger;\n}\n\nexport class PinoLogger extends MastraLogger {\n protected logger: pino.Logger;\n\n constructor(options: PinoLoggerOptions = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions;\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 let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname',\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 },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n {\n stream: prettyStream!,\n 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 {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions = {\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,"sources":["../src/pino.ts"],"names":["MastraLogger","pretty","pino","LogLevel"],"mappings":";;;;;;;;;;;;AA8BO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAmBA,mBAAA,CAAa;AAAA,EACjC,MAAA;AAAA,EAEV,WAAA,CAAY,OAAA,GAA6B,EAAC,EAAG;AAC3C,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,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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,MAAM,QAAA,EAA+C;AACnD,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,QAAQ,CAAA;AAC5C,IAAA,MAAM,YAAA,GAA0C;AAAA,MAC9C,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,UAAA,EAAY,MAAA,CAAO,WAAA,CAAY,IAAA,CAAK,UAAU,CAAA;AAAA,MAC9C,OAAA,EAAS;AAAA,KACX;AACA,IAAA,OAAO,IAAI,YAAW,YAAY,CAAA;AAAA,EACpC;AAAA,EAEA,KAAA,CAAM,OAAA,EAAiB,IAAA,GAA4B,EAAC,EAAS;AAC3D,IAAA,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 {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\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\ninterface PinoLoggerInternalOptions extends PinoLoggerOptions {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger;\n}\n\nexport class PinoLogger extends MastraLogger {\n protected logger: pino.Logger;\n\n constructor(options: PinoLoggerOptions = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions;\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',\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 },\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 {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions = {\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"]}
package/dist/index.js CHANGED
@@ -12,8 +12,9 @@ var PinoLogger = class _PinoLogger extends MastraLogger {
12
12
  this.logger = internalOptions._logger;
13
13
  return;
14
14
  }
15
+ const shouldPrettyPrint = options.prettyPrint ?? true;
15
16
  let prettyStream = void 0;
16
- if (!options.overrideDefaultTransports) {
17
+ if (!options.overrideDefaultTransports && shouldPrettyPrint) {
17
18
  prettyStream = pretty({
18
19
  colorize: true,
19
20
  levelFirst: true,
@@ -36,10 +37,7 @@ var PinoLogger = class _PinoLogger extends MastraLogger {
36
37
  stream: transport,
37
38
  level: options.level || LogLevel.INFO
38
39
  })),
39
- {
40
- stream: prettyStream,
41
- level: options.level || LogLevel.INFO
42
- }
40
+ ...prettyStream ? [{ stream: prettyStream, level: options.level || LogLevel.INFO }] : []
43
41
  ])
44
42
  );
45
43
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pino.ts"],"names":[],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AA,IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,IAAA,EAAM,OAAO,CAAA;AAAA,EACjC;AACF","file":"index.js","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 {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\n}\n\ninterface PinoLoggerInternalOptions extends PinoLoggerOptions {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger;\n}\n\nexport class PinoLogger extends MastraLogger {\n protected logger: pino.Logger;\n\n constructor(options: PinoLoggerOptions = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions;\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 let prettyStream: ReturnType<typeof pretty> | undefined = undefined;\n if (!options.overrideDefaultTransports) {\n prettyStream = pretty({\n colorize: true,\n levelFirst: true,\n ignore: 'pid,hostname',\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 },\n options.overrideDefaultTransports\n ? options?.transports?.default\n : transportsAry.length === 0\n ? prettyStream\n : pino.multistream([\n ...transportsAry.map(([, transport]) => ({\n stream: transport,\n level: options.level || LogLevel.INFO,\n })),\n {\n stream: prettyStream!,\n 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 {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions = {\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,"sources":["../src/pino.ts"],"names":[],"mappings":";;;;;AA8BO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAmB,YAAA,CAAa;AAAA,EACjC,MAAA;AAAA,EAEV,WAAA,CAAY,OAAA,GAA6B,EAAC,EAAG;AAC3C,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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IAAA,CAAK,MAAA,CAAO,KAAA,CAAM,QAAQ,CAAA;AAC5C,IAAA,MAAM,YAAA,GAA0C;AAAA,MAC9C,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,UAAA,EAAY,MAAA,CAAO,WAAA,CAAY,IAAA,CAAK,UAAU,CAAA;AAAA,MAC9C,OAAA,EAAS;AAAA,KACX;AACA,IAAA,OAAO,IAAI,YAAW,YAAY,CAAA;AAAA,EACpC;AAAA,EAEA,KAAA,CAAM,OAAA,EAAiB,IAAA,GAA4B,EAAC,EAAS;AAC3D,IAAA,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.js","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 {\n name?: string;\n level?: LogLevel;\n transports?: TransportMap;\n overrideDefaultTransports?: boolean;\n formatters?: pino.LoggerOptions['formatters'];\n redact?: pino.LoggerOptions['redact'];\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\ninterface PinoLoggerInternalOptions extends PinoLoggerOptions {\n /** @internal Used internally for child loggers */\n _logger?: pino.Logger;\n}\n\nexport class PinoLogger extends MastraLogger {\n protected logger: pino.Logger;\n\n constructor(options: PinoLoggerOptions = {}) {\n super(options);\n\n const internalOptions = options as PinoLoggerInternalOptions;\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',\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 },\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 {\n const childPino = this.logger.child(bindings);\n const childOptions: PinoLoggerInternalOptions = {\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"]}
package/dist/pino.d.ts CHANGED
@@ -10,6 +10,13 @@ export interface PinoLoggerOptions {
10
10
  overrideDefaultTransports?: boolean;
11
11
  formatters?: pino.LoggerOptions['formatters'];
12
12
  redact?: pino.LoggerOptions['redact'];
13
+ /**
14
+ * When false, disables pino-pretty and outputs raw JSON.
15
+ * Useful when sending logs to aggregators like Datadog,
16
+ * Loki, or CloudWatch that expect single-line JSON per entry.
17
+ * @default true
18
+ */
19
+ prettyPrint?: boolean;
13
20
  }
14
21
  export declare class PinoLogger extends MastraLogger {
15
22
  protected logger: pino.Logger;
@@ -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;AAEp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",
6
6
  "files": [
@@ -65,20 +65,20 @@
65
65
  "author": "",
66
66
  "license": "Apache-2.0",
67
67
  "dependencies": {
68
- "pino": "^10.1.0",
68
+ "pino": "^10.3.1",
69
69
  "pino-pretty": "^13.1.3"
70
70
  },
71
71
  "devDependencies": {
72
- "@types/node": "22.19.7",
73
- "@vitest/coverage-v8": "4.0.12",
74
- "@vitest/ui": "4.0.12",
75
- "eslint": "^9.37.0",
72
+ "@types/node": "22.19.15",
73
+ "@vitest/coverage-v8": "4.0.18",
74
+ "@vitest/ui": "4.0.18",
75
+ "eslint": "^9.39.4",
76
76
  "tsup": "^8.5.1",
77
77
  "typescript": "^5.9.3",
78
- "vitest": "4.0.16",
79
- "@internal/lint": "0.0.60",
80
- "@internal/types-builder": "0.0.35",
81
- "@mastra/core": "1.5.0"
78
+ "vitest": "4.0.18",
79
+ "@internal/types-builder": "0.0.47",
80
+ "@internal/lint": "0.0.72",
81
+ "@mastra/core": "1.14.0"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "@mastra/core": ">=1.0.0-0 <2.0.0-0"