combineLoggers()
The combineLoggers()
function takes multiple logger instances and returns a single Logger that broadcasts messages to all underlying loggers. This is useful for writing logs to multiple destinations simultaneously.
Usage
import { createLogger, combineLoggers } from '@mastra/core';
const consoleLogger = createLogger({ type: 'CONSOLE', level: 'INFO' });
const fileLogger = createLogger({ type: 'FILE', dirPath: 'my-logs', level: 'INFO' });
const multiLogger = combineLoggers([consoleLogger, fileLogger]);
// This log entry is recorded by both the console and file loggers
multiLogger.info({ message: 'Server started', destinationPath: 'server', type: 'AGENT' });
Parameters
loggers:
Logger<BaseLogMessage>[]
An array of logger instances created by createLogger() or custom logger objects.