Created
November 7, 2016 21:51
-
-
Save alexdmejias/ec08520bbd913fc9715cd3e97e1c2d99 to your computer and use it in GitHub Desktop.
thing to understand the winston logging levels and formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const w = require('winston') | |
const chalk = require('chalk'); | |
w.level = 'silly'; | |
w.error('error log') | |
w.warn('warn log') | |
w.info('info log') | |
w.verbose('verbose log') | |
w.debug('debug log') | |
w.silly('silly log') | |
var formatterFunc = function (options) { | |
return `${chalk.bold['red']('events module')} [${w.config.colorize(options.level, options.level)}] ${options.message}` | |
}; | |
const l = new (w.Logger)({ | |
transports: [ | |
new (w.transports.Console)({ | |
colorize: true, | |
level: 'silly', | |
showLevel: true, | |
formatter: formatterFunc | |
// formatter: function (options) { | |
// return '>>>>' + options.message + (options.meta.postfix || '<<<<') | |
// } | |
}) | |
], | |
// rewriters: [(level, msg, meta) => { return '||||' + msg + '@@@@@' }], | |
// filters: [(level, msg, meta) => { return '||||' + msg + '@@@@@' }], | |
// filters: [(level, msg, meta) => { /* etc etc */ }] | |
}); | |
console.log('-----') | |
// l.level = 'silly'; | |
l.error('error log') | |
l.warn('warn log') | |
l.info('info log') | |
l.verbose('verbose log') | |
l.debug('debug log') | |
l.silly('silly log', 'wasda', 'wasd') | |
l.log('error', 'this is a log message') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment