karthick.k karthick.k - 1 year ago 184
Node.js Question

Log Rotation in Node.js?

In my web analytics, I am logging the data in plan text file. I want to rotate the log on daily basis because its logging too much data. Currently i am using bunyan to rotate the logs.

Problem facing

Its rotating the file correctly, but rotated log file are in the name
, etc. I want the file name to be

I can't able to edit the bunyan file to meet my requirement . Becoz we are installing the modules using

So my question is

Is there any other log rotation in node.js meets my requirement?

Answer Source

Winston does support log rotation using a date in the file name. Take a look at this pull request which adds the feature and was merged four months ago. Unfortunately the documentation isn't listed on the site, but there is another pull request pending to fix that. Based on that documentation, and the tests for the log rotation features, you should be able to just add it as a new Transport to enable the log rotation functionality. Something like the following:

winston.add(winston.transports.DailyRotateFile, {
  filename: './logs/my.log',
  datePattern: '.dd-MM-yyyy'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download