Skip to content

Commit 8f64745

Browse files
author
Matt Berther
committed
implement utc support for date substitution in filename
Resolves #231
1 parent a2609db commit 8f64745

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
2727
* **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)
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')
30+
* **utc**: Use UTC time for date in filename. (default: false)
3031

3132
## Usage
3233
``` js

daily-rotate-file.js

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

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

test/transport-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ describe('winston/transports/daily-rotate-file', function () {
9999

100100
describe('when using a filename or dirname', function () {
101101
var logDir = path.join(__dirname, 'logs');
102-
var now = moment().format('YYYY-MM-DD-HH');
102+
var now = moment().utc().format('YYYY-MM-DD-HH');
103103
var filename = path.join(logDir, 'application-' + now + '.log');
104104
var options = {
105105
json: true,
106106
dirname: logDir,
107107
filename: 'application-%DATE%.log',
108-
datePattern: 'YYYY-MM-DD-HH'
108+
datePattern: 'YYYY-MM-DD-HH',
109+
utc: true
109110
};
110111

111112
beforeEach(function (done) {

0 commit comments

Comments
 (0)