我想在一个文件中显示错误日志,在另一个文件中显示所有日志。为此,我写了两个文件传输,它们在编译时出现以下错误:
'use strict';
var winston = require('winston'),
config = require('./config');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({level:'debug',handleExceptions: true,prettyPrint: true,silent:false,timestamp: true,colorize: true,json: false}),
new (winston.transports.File)({ filename: './server/logs/bv_common.log',level:'debug',maxsize: 1024000,maxFiles: 10, handleExceptions: true,json: false}),
new (winston.transports.File)({ filename: './server/logs/bv_error.log',level:'debug',maxsize: 1024000,maxFiles: 10, handleExceptions: true,json: false,level:'error'})
]
});
module.exports = logger;
结果:
[ 'Error: Transport already attached: file',
答案 0 :(得分:11)
var logger = new (winston.Logger)({
exitOnError: false, //don't crash on exception
transports: [
new (winston.transports.Console)({level:'debug',handleExceptions: true,prettyPrint: true,silent:false,timestamp: true,colorize: true,json: false}),
new (winston.transports.File)({ filename: './server/logs/' + config.appname +'_common.log',name:'file.all',level:'debug',maxsize: 1024000,maxFiles: 10, handleExceptions: true,json: false}),
new (winston.transports.File)({ filename: './server/logs/' + config.appname +'_error.log',name:'file.error',level:'error',maxsize: 1024000,maxFiles: 10, handleExceptions: true,json: false})
]
});
上面的代码,尤其是共享传输的名称参数,我们可以为记录器使用多个文件传输。
答案 1 :(得分:9)
您收到此错误是因为您没有提供姓名'属性到您的文件传输。