Logger for cli apps and nutty middlewares
npm install --save nutty-log
var log = require('nutty-log');
//Set the minimum log level
log.level('info');
//Print an error message
log.error('My error message'); // --> [2017/01/26 11:39:54] [ERROR] My error message
//Print a debug message
log.debug('My debug message'); // Not printed, because log level is set to info or higher.
- Level 5:
fatal
. - Level 4:
error
. - Level 3:
warning
. - Level 2:
notice
. - Level 1:
info
. - Level 0:
debug
.
Set the minimum log level. Only messages with higher level will be printed in console.
Display a debug message in console. The message will be printed
log.debug('My debug message'); // --> [2017/01/26 12:00:48] [DEBUG] My debug message
Display an info message in console.
log.info('My info message'); // --> [2017/01/26 12:00:48] [INFO] My info message
Display a notice message in console.
log.notice('My notice message'); // --> [2017/01/26 12:00:48] [NOTICE] My notice message
Display a warning message in process.stderr
.
log.warning('My warning message'); // --> [2017/01/26 12:00:48] [WARNING] My warning message
Display an error message in process.stderr
.
log.error('My error message'); // --> [2017/01/26 12:00:48] [ERROR] My error message
Display a fatal message in process.stderr
.
log.fatal('My fatal message'); // --> [2017/01/26 12:00:48] [FATAL] My fatal message
Returns a string with the structure [yyyy/mm/dd hh:mm:ss] [LEVEL] message
.
Returns an array with the parsed messages in JSON format.
//Print in console
var msg1 = log.json('warning', 'This is my warning');
// [2017/01/27 15:28:19] [WARNING] This is my warning\n
var msg2 = log.json('error', 'This is my error');
// [2017/01/27 15:28:19] [ERROR] This is my error\n
//Full message
var message = msg1 + msg2;
// [2017/01/27 15:28:19] [WARNING] This is my warning\n[2017/01/27 15:28:19] [ERROR] This is my error\n
//Parse the message
log.parse(message)
// [
// { time: '2017/01/27 15:28:19', level: 'warning', message: 'This is my warning' },
// { time: '2017/01/27 15:28:19', level: 'error', message: 'This is my error' },
// ]
- nutty A small and minimal CLI framework.
MIT LICENSE © Josemi Juanes.