【发布时间】:2018-08-22 14:50:15
【问题描述】:
我正在尝试使用 Winston 为我的 express 服务器设置访问日志和错误日志,但我似乎做错了什么。
这是我对配置文件的尝试:
const winston = require('winston'),
fs = require('fs');
const tsFormat = () => (new Date()).toLocaleTimeString();
winston.loggers.add('errorLog', {
file: {
filename: '<path>/errors.log', //<path> is replaced by the
timestamp: tsFormat, //absolute path of the log
level: 'info'
}
});
winston.loggers.add('accessLog', {
file: {
filename: '<path>/access.log', //same as before
timestamp: tsFormat,
level: 'info'
}
});
这就是我将它包含在我的其他文件中的方式:
var winston = require('winston'),
accessLog = winston.loggers.get('accessLog'),
errorLog = winston.loggers.get('errorLog');
在我看来,这似乎遵循文档 (https://github.com/winstonjs/winston/tree/2.4.0#working-with-multiple-loggers-in-winston) 但是当我尝试登录时出现此错误:
[winston] Attempt to write logs with no transports {"message":"pls","level":"info"}
[winston] Attempt to write logs with no transports {"message":"Bad request: undefined","level":"warn"}
任何帮助将不胜感激,这几天我一直很困惑。
【问题讨论】:
标签: node.js express npm winston