6

我想在一个文件中显示错误日志,在另一个文件中显示所有日志。为此,我编写了两个文件传输,在编译时出现以下错误:

 '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',
4

2 回答 2

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})
]
  });

上面的代码,特别是共享传输的名称参数,我们可以为记录器使用多个文件传输。

于 2014-04-18T08:44:08.740 回答
9

您收到此错误是因为您没有为文件传输提供“名称”属性。

于 2014-09-24T20:01:52.503 回答