logging器不会根据需要保存所有日志信息 – 节点jsasynchronous

我有一个伟大的winstonlogging器:

var systemLogger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ timestamp: function () { return moment().format('D/MM/YYYY HH:mm:ss:SSS') }, colorize: true }), new (require('winston-daily-rotate-file'))({ filename: 'logs/-system.log', datePattern: 'dd-MM-yyyy', prepend: true, json: false, timestamp: function () { return moment().format('D/MM/YYYY HH:mm:ss:SSS') }, formatter: formatter }) ] }) 

我在我的程序中调用这个logging器:

 var systemLogger = require('./logging.js') var asyncTasks = [] asyncTasks.push(function(callback) { systemLogger.info('Saved the Updates', { 'URL': url }) callback() }) asyncTasks.push(function(callback) { systemLogger.info('Status Updates', { 'Status': status }) callback() }) async.parallel(asyncTasks, function(error, data) { if (!done) { process.exit(!error) } }) 

我尽可能地简化了我的代码,但是我的想法是,我在整个程序中生成了不同的日志消息,我将它们添加到数组中并且并行运行它们。

现在….这导致一个问题。 所有的日志消息被打印到控制台,但只有一个被保存到我的实际日志文件。 这是为什么?

我试图注释掉日志消息并重新运行程序,但是仍然只有一条消息被保存在上面的例子中。 任何帮助将不胜感激!

假设 – 这可能是因为我在同一时间将信息保存到同一个日志文件 – 但这只是两个小行,所以我认为如果它被打印在控制台,它应该也保存正确?

我尽可能完成了你的代码,并得到了这个。 代码工作正常,并logging在控制台和文件中没有错误。

运行节点v.4.4.5,如果可能的话。

如果有文件写入失败,则不在代码的这一部分。

test.js

 'use strict'; //Dependencies const async = require('async'), systemLogger = require('./logging.js'); //Test variables const url = 'redblueyellow', status = 'goldsilvercrystal'; let asyncTasks = []; asyncTasks.push(function(callback) { systemLogger.info('Saved the Updates', { 'URL': url }); callback(); }); asyncTasks.push(function(callback) { systemLogger.info('Status Updates', { 'Status': status }); callback(); }) async.parallel(asyncTasks, function(error, data) { console.log('error: ' + error); console.log('data: ' + data); }); 

logging.js

 'use strict'; //Dependencies const winston = require('winston'), moment = require('moment'); //Export let systemLogger = module.exports = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ timestamp: function () { return moment().format('D/MM/YYYY HH:mm:ss:SSS') }, colorize: true }), new (require('winston-daily-rotate-file'))({ filename: 'logs/-system.log', datePattern: 'dd-MM-yyyy', prepend: true, json: false, timestamp: function () { return moment().format('D/MM/YYYY HH:mm:ss:SSS') }/*, formatter: formatter*/ }) ] });