Logging with happiness
npm install n-log
'use strict';
const log = require('n-log');
log.debug('bala');
// [2016-03-01T06:34:19.689Z] DEBUG "bala"
log.info('balabala');
// [2016-03-01T06:34:19.692Z] INFO "balabala"
log.error(new Error('bala'));
// [2016-03-01T06:34:19.692Z] ERROR {"name":"Error","message":"bala","stack":"Error: bala\n at Object.<anonymous>...}
- 0 EMERGENCY
- 1 ALERT
- 2 CRITICAL
- 3 ERROR
- 4 WARNING
- 5 NOTICE
- 6 INFO
- 7 DEBUG
Set the stdout, by default it is process.stdout
.
Set the stderr, by default it is process.stderr
.
Set the log level, all logs whose level are higher than this will be ignored, by default it is 7
.
- time: The time object, formatted by
log._formatTime
. - level: The level of this log, if it's a no level log, it will be
null
. - message: Content of the log, formatted by
log._stringify
.
Compose the output, by default it is [time] level message
.
- time: The time object, created by
new Date()
.
Format the time which will be passed to log._compose
, by default it is [time.toISOString()]
- message: The argument passed to the log methods.
The method to stringify the message. If the log methods is called with not a single argument, this method will be call lots of times.
- error: the object passed to the log method whose level is lower than 4.
The method to stringify the error, when it is passed to the log method whose level is lower than 4, before the it is passed to log._stringify
method, it will be errorify by this method first. If the log methods is called with not a single argument, this method will be call lots of times.