Skip to content

Getting started

Installation

Install with:

pnpm add leekslazylogger
npm i leekslazylogger
yarn add leekslazylogger

And require it in your code:

const Logger = require('leekslazylogger');
const log = new Logger(options);

For options, see customisation.

Basic usage

Each log level can be used like this:

log.<level>(text[, colours[, ...extra]]);
  • text should be the string you want to log
  • colours is an optional array of [foregroundColour, backgroundColour]
  • extra are optional extras (like console.log('some %s text', 'awesome', {anObject: true}))

Examples

log.console('Hello world');

log.info('Ready.', ['magentaBright']);

log.info(Logger.format('Status: &aonline'));

A list of the default log levels can be found here. See customisation for information about custom log levels.

Colour overrides

If you want to override the colours of a particular line you can do so like this:

log.info('useful information', [foreground, background]);

foreground and background should be a resolvable colour.

Inline colours

Use the Logger.format() function to colour text using short codes ("&codes"):

log.console(Logger.format('&2this is green &4and this is red'));

Tip

You can use Logger.f() too.


Last update: April 1, 2021