Gathering detailed insights and metrics for @abtnode/file-stream-rotator
Gathering detailed insights and metrics for @abtnode/file-stream-rotator
Gathering detailed insights and metrics for @abtnode/file-stream-rotator
Gathering detailed insights and metrics for @abtnode/file-stream-rotator
npm install @abtnode/file-stream-rotator
Typescript
Module System
Node Version
NPM Version
77.8
Supply Chain
97.8
Quality
79
Maintenance
100
Vulnerability
100
License
Support custom file options when creating stream
Updated on Oct 27, 2018
Support separate audit files for multiple streams. Support for webpack
Updated on Oct 19, 2018
Reuse last log file when using filesize if below defined threshold
Updated on Feb 17, 2018
v0.0.7
Updated on Jul 13, 2016
JavaScript (58.69%)
TypeScript (41.31%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
145 Stars
95 Commits
70 Forks
56 Watchers
3 Branches
14 Contributors
Updated on May 15, 2025
Latest Version
0.6.3
Package Id
@abtnode/file-stream-rotator@0.6.3
Unpacked Size
51.75 kB
Size
12.31 kB
File Count
12
NPM Version
10.5.0
Node Version
21.7.3
Published on
Jun 28, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
NodeJS file stream rotator
To provide an automated rotation of Express/Connect logs or anything else that writes to a file on a regular basis that needs to be rotated based on date, a size limit or combination and remove old log files based on count or elapsed days.
npm install file-stream-rotator
{ flags: 'a' }
.1 // Default date added at the end of the file 2 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"daily", verbose: false}); 3 4 // Default date added using file pattern 5 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"daily", verbose: false}); 6 7 // Custom date added using file pattern using moment.js formats 8 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"daily", verbose: false, date_format: "YYYY-MM-DD"}); 9 10 // Rotate when the date format as calculated by momentjs is different (e.g monthly) 11 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"custom", verbose: false, date_format: "YYYY-MM"}); 12 13 // Rotate when the date format as calculated by momentjs is different (e.g weekly) 14 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"custom", verbose: false, date_format: "YYYY-ww"}); 15 16 // Rotate when the date format as calculated by momentjs is different (e.g AM/PM) 17 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"custom", verbose: false, date_format: "YYYY-MM-DD-A"}); 18 19 // Rotate on given minutes using the 'm' option i.e. 5m or 30m 20 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"5m", verbose: false}); 21 22 // Rotate on the hour or any specified number of hours 23 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false}); 24 25 // Rotate on the hour or any specified number of hours and keep 10 files 26 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: 10}); 27 28 // Rotate on the hour or any specified number of hours and keep 10 days 29 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: "10d"}); 30 31 // Rotate on the hour or any specified number of hours and keep 10 days and store the audit file in /tmp/log-audit.json 32 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: "10d", audit_file: "/tmp/log-audit.json"}); 33 34 // Rotate by file size only without date included in the name. Iteration will be added at the end. 35 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json"}); 36 37 // Rotate by file size only without date included in the name. Rotation added before the extension. 38 var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json". extension: ".log"}); 39 40 41 //..... 42 43 // Use new stream in express 44 app.use(express.logger({stream: rotatingLogStream, format: "default"})); 45 46 //..... 47
You can listen to the open, close, error and finish events generated by the open stream. You can also listen for custom events:
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.20
2052 7 Mar 13:10:00 2017 testlog-2017-03-07.13.09.log.21
3078 7 Mar 13:10:05 2017 testlog-2017-03-07.13.10.log.1
3078 7 Mar 13:10:08 2017 testlog-2017-03-07.13.10.log.2
3078 7 Mar 13:10:11 2017 testlog-2017-03-07.13.10.log.3
3078 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.
1 // Rotate every day or every 5 megabytes, whatever comes first. 2 var rotatingLogStream = require('file-stream-rotator').getStream( 3 { 4 filename:"/tmp/test-%DATE%.log", 5 frequency:"custom", 6 verbose: false, 7 date_format: "YYYY-MM-DD", 8 size: "5M" // its letter denominating the size is case insensitive 9 } 10 ); 11 rotatingLogStream.on('rotate',function(oldFile,newFile){ 12 // do something with old file like compression or delete older than X days. 13 })
The npm module for this library will be maintained by:
Thanks to the contributors below for raising PRs and everyone else that has raised issues to make the module better.
file-stream-rotator is licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 6/20 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More