Usage
const log = require('xxd-log');
const count = 5;
log.trace('count: %d', count);
log.debug('count:', count);
log.info(`count: ${count}`);
log.warn({count});
log.error(new Error(`count (${count}) is wrong.`));
log.fatal('Duang!');
console.log(log.chalk.red('This is red.'));
Configure
log.withLabel = false;
log.withTimestamp = false;
log.highlightStackTrace = false;
log.timestampFormat = 'HH:mm:ss.SSS';
log.withLabel = log.newLogger().options.withLabel;
const anotherLogger = log.newLogger({
withLabel: false,
withTimestamp: false,
highlightStackTrace: false,
})
You can change these options at any time in the process, and will take effect from next call of logging.
For further instruction of time format, please see moment.js documentation
Options List
Option | Type | Description |
---|
withTimestamp | boolean | Control if print message with timestamp before, default to true |
withLabel | boolean | Control if print message with label (indicating log level) before, default to true |
timestampFormat | string | Define how timestamp looks like, see moment.format() (http://momentjs.com/docs/#/displaying/format/), default to 'YYYY-MM-SS HH:mm:ss' |
highlightStackTrace | string | Control if highlight files in project (in process.cwd() , and not in node_modules ) in error stack trace. default to true |
Requirements
- Node.js >
6.0.0
- or Node.js >
4.0.0
with --harmony