A transport for winston which logs to a rotating file each day.
Installations
npm install winston-daily-rotate-file
Developer
winstonjs
Developer Guide
Module System
CommonJS
Min. Node Version
>=8
Typescript Support
Yes
Node Version
18.19.0
NPM Version
10.2.3
Statistics
899 Stars
248 Commits
155 Forks
24 Watching
2 Branches
47 Contributors
Updated on 21 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
227,843,805
Last day
5.5%
153,413
Compared to previous day
Last week
4.4%
832,931
Compared to previous week
Last month
7.6%
3,418,430
Compared to previous month
Last year
-38.4%
48,569,833
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
winston-daily-rotate-file
A transport for winston which logs to a rotating file. Logs can be rotated based on a date, size limit, and old logs can be removed based on count or elapsed days.
Starting with version 2.0.0, the transport has been refactored to leverage the file-stream-rotator module. Some of the options in the 1.x versions of the transport have changed. Please review the options below to identify any changes needed.
Compatibility
Please note that if you are using winston@2
, you will need to use winston-daily-rotate-file@3
. winston-daily-rotate-file@4
removed support for winston@2
.
Starting with version 5.0.0 this module also emits an "error" event for all low level filesystem error cases. Make sure to listen for this event to prevent crashes in your application.
This library should work starting with Node.js 8.x, but tests are only executed for Node.js 14+. Use on your own risk in lower Node.js versions.
Install
npm install winston-daily-rotate-file
Options
The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the logger, winston-daily-rotate-file
also accepts the following options:
- frequency: A string representing the frequency of rotation. This is useful if you want to have timed rotations, as opposed to rotations that happen at specific moments in time. Valid values are '#m' or '#h' (e.g., '5m' or '3h'). Leaving this null relies on
datePattern
for the rotation times. (default: null) - datePattern: A string representing the moment.js date format to be used for rotating. The meta characters used in this string will dictate the frequency of the file rotation. For example, if your datePattern is simply 'HH' you will end up with 24 log files that are picked up and appended to every day. (default: 'YYYY-MM-DD')
- zippedArchive: A boolean to define whether or not to gzip archived log files. (default: 'false')
- filename: Filename to be used to log to. This filename can include the
%DATE%
placeholder which will include the formatted datePattern at that point in the filename. (default: 'winston.log.%DATE%') - dirname: The directory name to save log files to. (default: '.')
- stream: Write directly to a custom stream and bypass the rotation capabilities. (default: null)
- maxSize: Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number. (default: null)
- maxFiles: Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. It uses auditFile to keep track of the log files in a json format. It won't delete any file not contained in it. It can be a number of files or number of days (default: null)
- options: An object resembling https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options indicating additional options that should be passed to the file stream. (default:
{ flags: 'a' }
) - auditFile: A string representing the path of the audit file, passed directly to file-stream-rotator as
audit_file
. If not specified, a file name is generated that includes a hash computed from the options object, and uses thedirname
option value as the directory. (default:<dirname>/.<optionsHash>-audit.json
) - utc: Use UTC time for date in filename. (default: false)
- extension: File extension to be appended to the filename. (default: '')
- createSymlink: Create a tailable symlink to the current active log file. (default: false)
- symlinkName: The name of the tailable symlink. (default: 'current.log')
- auditHashType: Use specified hashing algorithm for audit. (default: 'sha256')
- level: Name of the logging level that will be used for the transport, if not specified option from
createLogger
method will be used
Usage
1 var winston = require('winston'); 2 require('winston-daily-rotate-file'); 3 4 var transport = new winston.transports.DailyRotateFile({ 5 level: 'info', 6 filename: 'application-%DATE%.log', 7 datePattern: 'YYYY-MM-DD-HH', 8 zippedArchive: true, 9 maxSize: '20m', 10 maxFiles: '14d' 11 }); 12 13 transport.on('error', error => { 14 // log or handle errors here 15 }); 16 17 transport.on('rotate', (oldFilename, newFilename) => { 18 // do something fun 19 }); 20 21 var logger = winston.createLogger({ 22 transports: [ 23 transport 24 ] 25 }); 26 27 logger.info('Hello World!'); 28
using multiple transports
1 var winston = require('winston'); 2 require('winston-daily-rotate-file'); 3 4 var transport1 = new winston.transports.DailyRotateFile({ 5 filename: 'application-%DATE%.log', 6 datePattern: 'YYYY-MM-DD-HH', 7 zippedArchive: true, 8 maxSize: '20m', 9 maxFiles: '14d' 10 }); 11 12 var transport2 = new winston.transports.DailyRotateFile({ 13 level: 'error', 14 filename: 'application-error-%DATE%.log', 15 datePattern: 'YYYY-MM-DD-HH', 16 zippedArchive: true, 17 maxSize: '20m', 18 maxFiles: '14d' 19 }); 20 21 transport1.on('error', error => { 22 // log or handle errors here 23 }); 24 25 transport2.on('error', error => { 26 // log or handle errors here 27 }); 28 29 transport1.on('rotate', function(oldFilename, newFilename) { 30 // do something fun 31 }); 32 33 transport2.on('rotate', function(oldFilename, newFilename) { 34 // do something fun 35 }); 36 37 var logger = winston.createLogger({ 38 level: 'info' 39 transports: [ 40 transport1, // will be used on info level 41 transport2 // will be used on error level 42 ] 43 }); 44 45 logger.info('Hello World!'); 46 logger.error('Hello Error!'); 47
ES6
1import * as winston from 'winston'; 2import 'winston-daily-rotate-file'; 3 4 5const transport = new winston.transports.DailyRotateFile({ 6 filename: 'application-%DATE%.log', 7 datePattern: 'YYYY-MM-DD-HH', 8 zippedArchive: true, 9 maxSize: '20m', 10 maxFiles: '14d' 11}); 12 13transport.on('error', error => { 14 // log or handle errors here 15}); 16 17transport.on('rotate', (oldFilename, newFilename) => { 18 // do something fun 19}); 20 21const logger = winston.createLogger({ 22 transports: [ 23 transport 24 ] 25}); 26 27logger.info('Hello World!');
Typescript
1 2import * as winston from 'winston'; 3import DailyRotateFile from 'winston-daily-rotate-file'; 4 5const transport: DailyRotateFile = new DailyRotateFile({ 6 filename: 'application-%DATE%.log', 7 datePattern: 'YYYY-MM-DD-HH', 8 zippedArchive: true, 9 maxSize: '20m', 10 maxFiles: '14d' 11}); 12 13transport.on('error', error => { 14 // log or handle errors here 15}); 16 17 18transport.on('rotate', (oldFilename, newFilename) => { 19 // do something fun 20}); 21 22const logger = winston.createLogger({ 23 transports: [ 24 transport 25 ] 26}); 27 28logger.info('Hello World!');
This transport emits the following custom events:
- new: fired when a new log file is created. This event will pass one parameter to the callback (newFilename).
- rotate: fired when the log file is rotated. This event will pass two parameters to the callback (oldFilename, newFilename).
- archive: fired when the log file is archived. This event will pass one parameter to the callback (zipFilename).
- logRemoved: fired when a log file is removed from the file system. This event will pass one parameter to the callback (removedFilename).
-
- error: fired when a low level filesystem error happens (e.g. EACCESS)
LICENSE
MIT
AUTHOR: Charlie Robbins
MAINTAINER: Matt Berther
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
Found 7/20 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:65: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:98: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-and-release.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/winstonjs/winston-daily-rotate-file/test-and-release.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test-and-release.yml:46
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 3 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test-and-release.yml:1
- Info: no jobLevel write permissions found
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Score
3.3
/10
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 MoreOther packages similar to winston-daily-rotate-file
nest-logger-daily-rotate
Enhance nest's default logger with winston-daily-rotate-file
@abtnode/winston-daily-rotate-file
A transport for winston which logs to a rotating file each day.
@zwave-js/winston-daily-rotate-file
A transport for winston which logs to a rotating file each day.
file-stream-rotator
Automated stream rotation useful for log files