A pre-connfigured instance of loglevel with colors and prefixes
The default loglevel is DEBUG
, but this can be configured either by setting the
env var LOGLEVEL
, or passing the log level in as a second argument.
The possible log levels are:
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
npm install loglevel-colors
const log = require('loglevel-colors')('Sample');
log.trace(`I'm a trace message!`);
log.debug(`I'm a debug message!`);
log.info(`I'm a info message!`);
log.warn(`I'm a warn message!`);
log.error(`I'm a error message!`);
[Sample] DEBUG: I'm a debug message!
[Sample] INFO: I'm a info message!
[Sample] WARN: I'm a warn message!
[Sample] ERROR: I'm a error message!
const log = require('loglevel-colors')('Sample', 'WARN');
log.trace(`I'm a trace message!`);
log.debug(`I'm a debug message!`);
log.info(`I'm a info message!`);
log.warn(`I'm a warn message!`);
log.error(`I'm a error message!`);
[Sample] WARN: I'm a warn message!
[Sample] ERROR: I'm a error message!