Skip to content

Customisation

See defaults.js for defaults.

Logger options

Types:

{
    name?: String,
    timestamp?: String,
    logToFile?: Boolean,
    splitFile?: Boolean,
    header?: Boolean,
    maxAge?: Number,
    daily?: Boolean,
    keepSilent?: Boolean,
    debug?: Boolean,
    directory?: String,
    levels?: Object
}
name

name

The name of your program. Appears in log file headers.

timestamp

timestamp

A dtf timestamp format.

logToFile

logToFile

Create and use log files?

splitFile

splitFile

Split log file into separate stdout and stderr files?

header

Include the header in log files?

maxAge

maxAge

The number of days to keep log files for.

daily

daily

Create 1 file per day? Otherwise creates 1 file per run.

keepSilent

keepSilent

Disable the logger's startup messages?

debug

debug

If false, log levels with the type of debug are ignored.

directory

directory

The logs directory path.

levels

levels

Customise your logger's log levels.

Log levels

{
    type?: String,
    format: String | Function
}

Use the levels option to override the defaults, or create new ones.

Each level must have a format property which is either a string, or a function which returns a string.

The format may contain short codes and the following placeholders:

  • {timestamp} - The formatted timestamp string
  • {text} - The text to be logged

To use RGB, HEX, or 8Bit colours you need to import leeks.js. You don't need to install it as it a dependency of leekslazylogger.

Each level can optionally have a type property: console[type](...).

Example

const Logger = require('leekslazylogger');
const log = new Logger({
    levels: {
        db: {
            type: 'debug', // optional
            format: '[{timestamp} | DEBUG] &7[DATABASE]&r {text}'
        }
    }
});
log.db('Some boring information about the database');

More examples.


Last update: July 18, 2021