Skip to content

Commit

Permalink
implement utc support for date substitution in filename
Browse files Browse the repository at this point in the history
Resolves #231
  • Loading branch information
Matt Berther committed Sep 5, 2019
1 parent a2609db commit 8f64745
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
* **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. (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 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)

## 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 @@ -86,7 +86,8 @@ var DailyRotateFile = function (options) {
max_logs: options.maxFiles,
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'}
file_options: options.options ? options.options : {flags: 'a'},
utc: options.utc ? options.utc : false
});

this.logStream.on('new', function (newFile) {
Expand Down
5 changes: 3 additions & 2 deletions test/transport-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,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().format('YYYY-MM-DD-HH');
var now = moment().utc().format('YYYY-MM-DD-HH');
var filename = path.join(logDir, 'application-' + now + '.log');
var options = {
json: true,
dirname: logDir,
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH'
datePattern: 'YYYY-MM-DD-HH',
utc: true
};

beforeEach(function (done) {
Expand Down

0 comments on commit 8f64745

Please sign in to comment.