Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log Rotation in Node.js?

Tags:

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

Problem I am facing

It is rotating the file correctly, but rotated log file are in the name log.0, log.1, etc. I want the file name to be log.05-08-2013, log.04-08-2013

I can't edit the source of the bunyanpackage because we are installing the modules using package.json via NPM.

So my question is - Is there any other log rotation in Node.js that meets my requirement?

like image 583
karthick Avatar asked Aug 05 '13 10:08

karthick


People also ask

What is meant by log rotation?

In information technology, log rotation is an automated process used in system administration in which log files are compressed, moved (archived), renamed or deleted once they are too old or too big (there can be other metrics that can apply here).

How do you rotate log forces?

If you want to force Logrotate to rotate the log file when it otherwise would not have, use the --force flag: logrotate /home/sammy/logrotate. conf --state /home/sammy/logrotate-state --verbose --force.

How do you find the log rotation?

To verify if a particular log is indeed rotating or not and to check the last date and time of its rotation, check the /var/lib/logrotate/status file. This is a neatly formatted file that contains the log file name and the date on which it was last rotated. You'll find this file as /var/lib/logrotate.


1 Answers

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' }); 
like image 69
Timothy Strimple Avatar answered Sep 20 '22 20:09

Timothy Strimple