setDefaultLoggerOptions
The setDefaultLoggerOptions function allows you to set global default options for all newly created logger instances. These defaults are applied if they are not explicitly overridden when calling createLogger.
import { setDefaultLoggerOptions } from '@archibald/log';
setDefaultLoggerOptions({
colorize: true,
transporters: [{ type: 'Console' }]
});
Options
| Name | Type | Description |
|---|---|---|
| colorize | boolean | Enable or disable colored output (mainly for server-side logging). |
| transporters | TransporterParameters | An array of transporter configurations or instances. |
Behavior
When setDefaultLoggerOptions is called, it stores the provided options globally.
- New Loggers: Any logger created after this call will use these defaults unless specific values are passed to
createLogger. - Existing Loggers: When
createLoggeris called for an existing logger (same prefix and format), it will also be updated with the current global defaults if they were not explicitly overridden in that call.
Example
import { createLogger, setDefaultLoggerOptions } from '@archibald/log';
// Set global defaults
setDefaultLoggerOptions({
colorize: true,
transporters: [{ type: 'Console' }]
});
// This logger will use global defaults (colorize: true)
const logger = createLogger({ prefix: 'my-module' });
// This logger overrides global defaults
const customLogger = createLogger({
prefix: 'auth',
colorize: false
});