Skip to content

Customisation

Options can be set on initialisation, but are not required. You can also use the options setter to set options after initialisation. The object will be merged deeply with the existing (or default) options.

log.error.http('this will throw an error');
log.options = {
    // in this example only `namespaces` is modified,
    // so `levels` and `transports` are preserved from existing/default options
    namespaces: ['http']
};
log.success.http('this works');

Logger options

Defaults

See defaults.ts

Types:

interface Partial<LoggerOptions> {
    levels?: {
        [name: string]: string
    },
    namespaces?: Array<string>,
    transports?: Array<Transport>
}

levels

Default
levels: {
    debug: 'info',
    verbose: 'info',
    info: 'info',
    success: 'info',
    warn: 'warn',
    notice: 'warn',
    error: 'error',
    critical: 'error'
}

You shouldn't need to change these. If you do, you're probably using levels incorrectly and you should look at namespaces.

namespaces

Default
namespaces: []

Use namespaces to separate your logs into to logical areas (eg. log.info.exampleNamespace())

transports

Default
transports: [
    new ConsoleTransport(),
    new FileTransport()
]

Transports are where the heavy lifting is done. When you use a log function, a log object is passed to the write function of each transport with a matching log level.


Last update: November 16, 2023