Overview
Mastra’s logging system:- Automatically correlates logs with traces and spans
- Supports multiple log levels (debug, info, warn, error, fatal)
- Captures structured data with each log message
- Works with any logger that implements the
LoggerContextinterface
Basic Usage
Default Logger
Mastra includes a console logger by default:Log Levels
Available log levels in order of severity:Structured Logging
Adding Context
Include structured data with log messages:Automatic Trace Correlation
Logs automatically include trace and span IDs when logged within a traced operation:Custom Logger
Implementing LoggerContext
Create a custom logger by implementing theLoggerContext interface:
Winston Integration
Integrate with Winston logger:Pino Integration
Integrate with Pino logger:Log Format
ExportedLog Structure
Logs are exported with this structure:Example Log Entry
Best Practices
Use Appropriate Log Levels
Include Relevant Context
Structure Complex Data
Avoid Logging Sensitive Data
Querying Logs
If using an observability platform, query logs via the HTTP API:Next Steps
Tracing
Learn about OpenTelemetry tracing
Server API
Explore server routes and handlers