# Logging
[EN] Source: https://mastra.ai/docs/observability/logging

Mastra's logging system captures function execution, input data, and output responses in a structured format.

When deploying to Mastra Cloud, logs are shown on the [Logs](../deployment/mastra-cloud/observability) page. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.

## Configuring logs with PinoLogger

When [initializing a new Mastra project](../getting-started/installation) using the CLI, `PinoLogger` is included by default.

```typescript title="src/mastra/index.ts" showLineNumbers copy
import { Mastra } from "@mastra/core/mastra";
import { PinoLogger } from "@mastra/loggers";

export const mastra = new Mastra({
  // ...
  logger: new PinoLogger({
    name: "Mastra",
    level: "info",
  }),
});
```

> See the [PinoLogger](/reference/observability/logging/pino-logger) API reference for all available configuration options.

## Customizing logs

Mastra provides access to a logger instance via the `mastra.getLogger()` method, available inside both workflow steps and tools. The logger supports standard severity levels: `debug`, `info`, `warn`, and `error`.

### Logging from workflow steps

Within a workflow step, access the logger via the `mastra` parameter inside the `execute` function. This allows you to log messages relevant to the step’s execution.

```typescript {8-9} title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
import { createWorkflow, createStep } from "@mastra/core/workflows";
import { z } from "zod";

const step1 = createStep({
  //...
  execute: async ({ mastra }) => {

    const logger = mastra.getLogger();
    logger.info("workflow info log");

    return {
      output: ""
    };
  }
});

export const testWorkflow = createWorkflow({...})
  .then(step1)
  .commit();
```

### Logging from tools

Similarly, tools have access to the logger instance via the `mastra` parameter. Use this to log tool specific activity during execution.

```typescript {8-9} title="src/mastra/tools/test-tool.ts" showLineNumbers copy
import { createTool } from "@mastra/core/tools";
import { z } from "zod";

export const testTool = createTool({
  // ...
  execute: async ({ mastra }) => {
    const logger = mastra?.getLogger();
    logger?.info("tool info log");

    return {
      output: "",
    };
  },
});
```

### Logging with additional data

Logger methods accept an optional second argument for additional data. This can be any value, such as an object, string, or number.

In this example, the log message includes an object with a key of `agent` and a value of the `testAgent` instance.

```typescript {11} title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
import { createWorkflow, createStep } from "@mastra/core/workflows";
import { z } from "zod";

const step1 = createStep({
  //...
  execute: async ({ mastra }) => {

    const testAgent = mastra.getAgent("testAgent");

    const logger = mastra.getLogger();
    logger.info("workflow info log", { agent: testAgent });

    return {
      output: ""
    };
  }
});

export const testWorkflow = createWorkflow({...})
  .then(step1)
  .commit();
```


---
title: "Next.js Tracing | Observability"
description: "Set up OpenTelemetry tracing for Next.js applications"
---