Logger Instance

A Logger instance is created by createLogger() or combineLoggers() and provides methods to record events at various severity levels. Depending on the logger type, messages may be written to the console, file, or an external service.

Example

// Using a console logger
const logger = createLogger({ type: 'CONSOLE', level: 'INFO' });
 
logger.debug('Debug message'); // Won't be logged because level is INFO
logger.info({ message: 'User action occurred', destinationPath: 'user-actions', type: 'AGENT' }); // Logged
logger.error('An error occurred'); // Logged as ERROR

Methods

debug:

(message: BaseLogMessage | string, ...args: any[]) => void | Promise<void>
Write a DEBUG-level log. Only recorded if level ≤ DEBUG.

info:

(message: BaseLogMessage | string, ...args: any[]) => void | Promise<void>
Write an INFO-level log. Only recorded if level ≤ INFO.

warn:

(message: BaseLogMessage | string, ...args: any[]) => void | Promise<void>
Write a WARN-level log. Only recorded if level ≤ WARN.

error:

(message: BaseLogMessage | string, ...args: any[]) => void | Promise<void>
Write an ERROR-level log. Only recorded if level ≤ ERROR.

cleanup?:

() => Promise<void>
Cleanup resources held by the logger (e.g., network connections for Upstash). Not all loggers implement this.

Note: Some loggers require a BaseLogMessage object (with message, destinationPath, type fields). For instance, the File and Upstash loggers need structured messages.


MIT 2025 © Nextra.