1
votes

I'm trying to setup a simple daily rotation log write with:

// Create file transport
transports.push(new winston.transports.DailyRotateFile({
  name: 'file',
  datePattern: '.yyyy-MM-ddTHH',
  filename: path.join(logPath, 'http')
}));

// Create new logger
var logger = new winston.Logger({
  transports: transports
});

It's creating the log file just fine, however logger.info(some_data) doesn't write anything to the log.

Any thoughts, or even another solution?

1
Not seeing where in your code log.info(some_data) is used or where the variable log is instantiated. I do see logger, but not log. - AlexMA
sorry, corrected, it was logger.info - Fluidbyte
Assuming it's not a Winston bug, some_data is not empty, and the logger is ready, either an error should have been generated or the file that was written to is somewhere you did not expect. Perhaps insert a logger.on('error', function (err) { /* Do Something */ }); and see if an error is being generated? - AlexMA
Or try a console.log(some_data) to see if some_data actually contains data. Or use a string for logger testing. Another solution could be to add the log level for the transport. If it is set to error for example, you wouldn't see info log requests. - atripes

1 Answers

2
votes

This one works with minute rotation:

var winston = require('winston');


var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.DailyRotateFile)({ filename: 'logFile', datePattern: '.yyyy-MM-dd_HH-mm' })
  ]
});


logger.info('Hello my friend');