下面的代码将所有请求记录到两个文件,其中一个是 JSON 格式。这具有将每个请求记录到控制台两次的副作用。这是为什么?我确定我使用 Winston 不正确,任何反馈将不胜感激。
var winston = require('winston');
winston.loggers.add('main_nojson', {
file: {
filename: '/home/stu/logs/winston_txt.log',
json: false
}
});
winston.loggers.add('main_json', {
file: {
filename: '/home/stu/logs/winston_json.log',
json: true
}
});
var winlog1 = winston.loggers.get('main_nojson');
var winlog2 = winston.loggers.get('main_json');
var winstonStream = {
write: function(message, encoding){
winlog1.info(message);
winlog2.info(message);
}
};
app.use(express.logger({stream:winstonStream, format: ':remote-addr - [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" :response-time' }));