formatter for console output with colour support and customizable formatting. handles timestamps, log levels, scopes, and applies appropriate colours.
const formatter = new ConsoleFormatter();const formatted = formatter.format(logEntry);console.log(formatted); Copy
const formatter = new ConsoleFormatter();const formatted = formatter.format(logEntry);console.log(formatted);
const formatter = new ConsoleFormatter({ timestamp: false, colourize: false, timeFormat: 'iso'}); Copy
const formatter = new ConsoleFormatter({ timestamp: false, colourize: false, timeFormat: 'iso'});
creates a new console formatter with the specified options.
formatting configuration options
formats a log entry into a human-readable string for console output.
the log entry to format
formatted string ready for console display
const entry = { level: LogLevel.INFO, message: 'user logged in', timestamp: new Date(), scope: ['auth'], args: [],};const formatted = formatter.format(entry);// "[2024-01-01 12:00:00] [INFO ] [auth] user logged in" Copy
const entry = { level: LogLevel.INFO, message: 'user logged in', timestamp: new Date(), scope: ['auth'], args: [],};const formatted = formatter.format(entry);// "[2024-01-01 12:00:00] [INFO ] [auth] user logged in"
formatter for console output with colour support and customizable formatting. handles timestamps, log levels, scopes, and applies appropriate colours.
Example: basic usage
Example: with custom options