Gathering detailed insights and metrics for file-stream-rotator
Gathering detailed insights and metrics for file-stream-rotator
Gathering detailed insights and metrics for file-stream-rotator
Gathering detailed insights and metrics for file-stream-rotator
@abtnode/file-stream-rotator
Automated stream rotation useful for log files
winston-daily-rotate-file
A transport for winston which logs to a rotating file each day.
@zwave-js/file-stream-rotator
Automated stream rotation useful for log files
tar-stream
tar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.
npm install file-stream-rotator
Support custom file options when creating stream
Published on 27 Oct 2018
Support separate audit files for multiple streams. Support for webpack
Published on 19 Oct 2018
Reuse last log file when using filesize if below defined threshold
Published on 17 Feb 2018
v0.0.7
Published on 13 Jul 2016
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
143 Stars
95 Commits
69 Forks
58 Watching
3 Branches
14 Contributors
Updated on 18 Oct 2024
JavaScript (58.69%)
TypeScript (41.31%)
Cumulative downloads
Total Downloads
Last day
6.9%
144,639
Compared to previous day
Last week
6%
791,863
Compared to previous week
Last month
8%
3,244,405
Compared to previous month
Last year
-36%
44,536,034
Compared to previous year
2
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
IMPORTANT NOTE
Since version 1, moment.js is not used anymore. The external dependencies have been removed. The date substitutions are done internally and only using numerical values for year, month, day, hour, minute, second. AM/PM is the only text replacement.
Frequency options have changed too.
{ flags: 'a' }
.1import * as FileStreamRotator from 'file-stream-rotator' 2 3var rotatingLogStream = FileStreamRotator.getStream({ 4 filename: "/tmp/test-%DATE%", 5 frequency: "daily", 6 date_format: "YYYY-MM-DD", 7 size: "100M", 8 max_logs: "10", 9 audit_file: "/tmp/audit.json", 10 extension: ".log", 11 create_symlink: true, 12 symlink_name: "tail-current.log", 13})
1// Default date added at the end of the file 2var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"daily", verbose: false}); 3 4// Default date added using file pattern 5var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"daily", verbose: false}); 6 7// Custom date added using file pattern using date format 8var 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 is different (e.g monthly) using Y (Year), M (Month) replacements 11var 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 is different (e.g AM/PM) using Y (Year), M (Month), D (Day), A (AM/PM) replacements 14var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test-%DATE%.log", frequency:"custom", verbose: false, date_format: "YYYY-MM-DD-A"}); 15 16// Rotate on given minutes using the 'm' option i.e. 5m or 30m 17var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"5m", verbose: false}); 18 19// Rotate on the hour or any specified number of hours 20var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false}); 21 22// Rotate on the hour or any specified number of hours and keep 10 files 23var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: 10}); 24 25// Rotate on the hour or any specified number of hours and keep 10 days 26var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: "10d"}); 27 28// Rotate on the hour or any specified number of hours and keep 10 days and store the audit file in /tmp/log-audit.json 29var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: "10d", audit_file: "/tmp/log-audit.json"}); 30 31// Rotate by file size only without date included in the name. Iteration will be added at the end. 32var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json"}); 33 34// Rotate by file size only without date included in the name. Rotation added before the extension. 35var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json", extension: ".log"}); 36 37 38//..... 39 40// Use new stream in express 41app.use(express.logger({stream: rotatingLogStream, format: "default"})); 42 43//..... 44
You can manually rotate the current open log to allow log archiving.
1rotatingLogStream.rotate(true)
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 2024-11-18
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