Reputation: 4182
As far as I understood has Winston a hierarchy in its logging levels. You can set the level with winston.level = 'error'
and all levels below should not be shown. Unfortunately I still get the logs of info and debug shown in my console.
Question 1):
How to really set winston to show me only the log level
Question 2)
Why is Debug anyways shown in the console, I configured it to show up in a log file (what it additionally does)
winston = require('winston')
winston.emitErrs = true
logger = new winston.Logger({
transports: [
new winston.transports.File({
level: 'info'
filename: 'logs/log.log'
handleExceptions: true
json: true
maxsize: 5242880 #5MB
maxFiles: 5
colorize: false
timestamp: true
}),
new winston.transports.Console({
level: 'debug'
handleExceptions: true
json: false
colorize: true
})
],
exitOnError: false
})
winston.level = 'error'
module.exports = logger
module.exports.stream = {
write: (message, encoding) ->
logger.info(message)
}
The code is basically from this tut: http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
Upvotes: 3
Views: 3219
Reputation: 4182
Now I got the concept. It logs everything up to the log level in the defined transport. So I guess it is not possible to stream debug just to console and info to the log without manipulating the order.
This does not log debug in the console:
new winston.transports.Console({
level: 'info'
handleExceptions: true
json: false
colorize: true
})
My first assumption was that I can specify a transport for each log level and then decide how much logging I want to have with:
winston.setLevels(winston.config.syslog.levels)
e.g. error to mongoDb info to log.log file debug to console
Upvotes: 4