Skip to content

Commit 54fe0f6

Browse files
author
Matt Berther
committed
add property to allow an extension to be added to the filename
Resolves #225 by allowing an extension to be added to the rotated filenames.
1 parent 56e63ea commit 54fe0f6

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
2828
* **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' }`)
2929
* **auditFile**: A string representing the name of the name of the audit file. This can be used to override the default filename which is generated by computing a hash of the options object. (default: '.<optionsHash>.json')
3030
* **utc**: Use UTC time for date in filename. (default: false)
31+
* **extension**: File extension to be appended to the filename. (default: '')
3132

3233
## Usage
3334
``` js

daily-rotate-file.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ var DailyRotateFile = function (options) {
8787
end_stream: true,
8888
audit_file: options.auditFile ? options.auditFile : path.join(self.dirname, '.' + hash(options) + '-audit.json'),
8989
file_options: options.options ? options.options : {flags: 'a'},
90-
utc: options.utc ? options.utc : false
90+
utc: options.utc ? options.utc : false,
91+
extension: options.extension ? options.extension : ''
9192
});
9293

9394
this.logStream.on('new', function (newFile) {

index.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ declare module "winston-daily-rotate-file" {
4747
options?: string | object;
4848

4949
/**
50-
* A string representing the name of the name of the audit file. (default: './hash-audit.json' )
50+
* A string representing the name of the name of the audit file. (default: './hash-audit.json')
5151
*/
52-
auditFile?: string
52+
auditFile?: string;
5353

5454
/**
5555
* A string representing the frequency of rotation. (default: 'custom')
5656
*/
57-
frequency?: string
57+
frequency?: string;
5858

5959
/**
6060
* A boolean whether or not to generate file name from "datePattern" in UTC format. (default: false)
6161
*/
6262
utc?: boolean;
63+
64+
/**
65+
* A string representing an extension to be added to the filename, if not included in the filename property. (default: '')
66+
*/
67+
extension?: string;
6368
}
6469
}
6570

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"rimraf": "2.6.3"
4141
},
4242
"dependencies": {
43-
"file-stream-rotator": "~0.5.0",
43+
"file-stream-rotator": "^0.5.4",
4444
"object-hash": "^1.3.0",
4545
"triple-beam": "^1.3.0",
4646
"winston-transport": "^4.2.0"

test/transport-tests.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ describe('winston/transports/daily-rotate-file', function () {
100100
describe('when using a filename or dirname', function () {
101101
var logDir = path.join(__dirname, 'logs');
102102
var now = moment().utc().format('YYYY-MM-DD-HH');
103-
var filename = path.join(logDir, 'application-' + now + '.log');
103+
var filename = path.join(logDir, 'application-' + now + '.testlog');
104104
var options = {
105105
json: true,
106106
dirname: logDir,
107-
filename: 'application-%DATE%.log',
107+
filename: 'application-%DATE%',
108108
datePattern: 'YYYY-MM-DD-HH',
109-
utc: true
109+
utc: true,
110+
extension: '.testlog'
110111
};
111112

112113
beforeEach(function (done) {

0 commit comments

Comments
 (0)