NodeJS file stream rotator
To provide an automated rotation of Express/Connect logs based on date.
npm install file-stream-rotator
// Default date added at the end of the filevar rotatingLogStream = ;// Default date added using file patternvar rotatingLogStream = ;// Custom date added using file pattern using moment.js formatsvar rotatingLogStream = ;// Rotate when the date format as calculated by momentjs is different (e.g monthly)var rotatingLogStream = ;// Rotate when the date format as calculated by momentjs is different (e.g weekly)var rotatingLogStream = ;// Rotate when the date format as calculated by momentjs is different (e.g AM/PM)var rotatingLogStream = ;// Rotate on given minutes using the 'm' option i.e. 5m or 30mvar rotatingLogStream = ;// Rotate on the hour or any specified number of hoursvar rotatingLogStream = ;//.....// Use new stream in expressapp;//.....
You can listen to the open, close, error and finish events generated by the open stream. You can also listen for custom events:
rotate: that will pass two parameters to the callback: oldFilename and newFilename new: that will pass two parameters to the callback: oldFilename and newFilename
You can also limit the size of each file by adding the size option using "k", "m" and "g" to specify the size of the file in kiloybytes, megabytes or gigabytes. When it rotates a file based on size, it will add a number to the end and increment it for every time the file rotates in the given period as shown below.
3078 7 Mar 13:09:58 2017 testlog-2017-03-07.13.09.log.202052 7 Mar 13:10:00 2017 testlog-2017-03-07.13.09.log.213078 7 Mar 13:10:05 2017 testlog-2017-03-07.13.10.log.13078 7 Mar 13:10:08 2017 testlog-2017-03-07.13.10.log.23078 7 Mar 13:10:11 2017 testlog-2017-03-07.13.10.log.33078 7 Mar 13:10:14 2017 testlog-2017-03-07.13.10.log.4
The example below will rotate files daily but each file will be limited to 5MB.
// Rotate every day or every 5 megabytes, whatever comes first.var rotatingLogStream =;rotatingLogStream
The npm module for this library will be maintained by:
file-stream-rotator is licensed under the MIT license.