M
Mastraโ€ข6d ago
Omar

Disable Colors for PinoLogger

I am using pinoLogger and I wonder how can I disable the colors and modify the formatting (such as adding filename:linenumber)
4 Replies
LekoArts
LekoArtsโ€ข6d ago
Hi! Here's how we internally define the pino logger: https://github.com/mastra-ai/mastra/blob/main/packages/loggers/src/pino.ts You can customize the formatting with the formatters option: https://mastra.ai/reference/observability/logging/pino-logger
import { Mastra } from '@mastra/core/mastra';
import { PinoLogger } from '@mastra/loggers';

export const mastra = new Mastra({
logger: new PinoLogger({
name: 'Chef',
level: 'debug',
formatters: {
bindings: (bindings) => {
console.log('Custom Bindings Formatter:', bindings)
return bindings
},
log: (log) => {
console.log('Custom Log Formatter:', log)
return log
},
level: (level) => {
console.log('Custom Level Formatter:', level)
return { level }
}
}
}),
});
import { Mastra } from '@mastra/core/mastra';
import { PinoLogger } from '@mastra/loggers';

export const mastra = new Mastra({
logger: new PinoLogger({
name: 'Chef',
level: 'debug',
formatters: {
bindings: (bindings) => {
console.log('Custom Bindings Formatter:', bindings)
return bindings
},
log: (log) => {
console.log('Custom Log Formatter:', log)
return log
},
level: (level) => {
console.log('Custom Level Formatter:', level)
return { level }
}
}
}),
});
For example returns this
Custom Log Formatter: {
strategy: 'batch-with-updates',
batchSize: 8,
flushReason: 'time',
durationMs: 17,
outOfOrderCount: undefined
}
DEBUG [2025-12-02 09:07:15.210 +0100] (Chef): Batch flushed
strategy: "batch-with-updates"
batchSize: 8
flushReason: "time"
durationMs: 17
Custom Log Formatter: {
strategy: 'batch-with-updates',
batchSize: 8,
flushReason: 'time',
durationMs: 17,
outOfOrderCount: undefined
}
DEBUG [2025-12-02 09:07:15.210 +0100] (Chef): Batch flushed
strategy: "batch-with-updates"
batchSize: 8
flushReason: "time"
durationMs: 17
GitHub
mastra/packages/loggers/src/pino.ts at main ยท mastra-ai/mastra
The TypeScript AI agent framework. โšก Assistants, RAG, observability. Supports any LLM: GPT-4, Claude, Gemini, Llama. - mastra-ai/mastra
Reference: PinoLogger | Observability | Mastra Docs
Documentation for PinoLogger, which provides methods to record events at various severity levels.
LekoArts
LekoArtsโ€ข6d ago
If you want to disable the color output, you need to set overrideDefaultTransports (see https://github.com/mastra-ai/mastra/blob/main/packages/loggers/src/pino.ts#L25) and define a default transport (see https://github.com/mastra-ai/mastra/blob/main/packages/loggers/src/pino.ts#L43-L44)
GitHub
mastra/packages/loggers/src/pino.ts at main ยท mastra-ai/mastra
The TypeScript AI agent framework. โšก Assistants, RAG, observability. Supports any LLM: GPT-4, Claude, Gemini, Llama. - mastra-ai/mastra
LekoArts
LekoArtsโ€ข6d ago
Lastly, you could also try the NO_COLOR variable: https://no-color.org/
Mastra Triager
Mastra Triagerโ€ข6d ago
๐Ÿ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10747 ๐Ÿ” If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. ๐Ÿ™ Thank you for helping us improve Mastra!

Did you find this page helpful?