Skip to content

Commit

Permalink
add property to allow an extension to be added to the filename
Browse files Browse the repository at this point in the history
Resolves #225 by allowing an extension to be added to the rotated filenames.
  • Loading branch information
Matt Berther committed Sep 6, 2019
1 parent 56e63ea commit 54fe0f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
* **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 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')
* **utc**: Use UTC time for date in filename. (default: false)
* **extension**: File extension to be appended to the filename. (default: '')

## Usage
``` js
Expand Down
3 changes: 2 additions & 1 deletion daily-rotate-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ var DailyRotateFile = function (options) {
end_stream: true,
audit_file: options.auditFile ? options.auditFile : path.join(self.dirname, '.' + hash(options) + '-audit.json'),
file_options: options.options ? options.options : {flags: 'a'},
utc: options.utc ? options.utc : false
utc: options.utc ? options.utc : false,
extension: options.extension ? options.extension : ''
});

this.logStream.on('new', function (newFile) {
Expand Down
11 changes: 8 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,24 @@ declare module "winston-daily-rotate-file" {
options?: string | object;

/**
* A string representing the name of the name of the audit file. (default: './hash-audit.json' )
* A string representing the name of the name of the audit file. (default: './hash-audit.json')
*/
auditFile?: string
auditFile?: string;

/**
* A string representing the frequency of rotation. (default: 'custom')
*/
frequency?: string
frequency?: string;

/**
* A boolean whether or not to generate file name from "datePattern" in UTC format. (default: false)
*/
utc?: boolean;

/**
* A string representing an extension to be added to the filename, if not included in the filename property. (default: '')
*/
extension?: string;
}
}

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"rimraf": "2.6.3"
},
"dependencies": {
"file-stream-rotator": "~0.5.0",
"file-stream-rotator": "^0.5.4",
"object-hash": "^1.3.0",
"triple-beam": "^1.3.0",
"winston-transport": "^4.2.0"
Expand Down
7 changes: 4 additions & 3 deletions test/transport-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ describe('winston/transports/daily-rotate-file', function () {
describe('when using a filename or dirname', function () {
var logDir = path.join(__dirname, 'logs');
var now = moment().utc().format('YYYY-MM-DD-HH');
var filename = path.join(logDir, 'application-' + now + '.log');
var filename = path.join(logDir, 'application-' + now + '.testlog');
var options = {
json: true,
dirname: logDir,
filename: 'application-%DATE%.log',
filename: 'application-%DATE%',
datePattern: 'YYYY-MM-DD-HH',
utc: true
utc: true,
extension: '.testlog'
};

beforeEach(function (done) {
Expand Down

0 comments on commit 54fe0f6

Please sign in to comment.