【发布时间】:2015-06-23 05:34:46
【问题描述】:
据我了解,Winston 的日志记录级别具有层次结构。您可以使用winston.level = 'error' 设置级别,并且不应显示以下所有级别。不幸的是,我的控制台中仍然显示了信息和调试日志。
问题 1):
如何真正设置winston只显示日志级别
问题 2)
为什么调试仍然显示在控制台中,我将其配置为显示在日志文件中(它还做了什么)
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)
}
代码基本上来自这个 tut: http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
【问题讨论】: