Skip to content

Commit 9bd80b8

Browse files
author
Matt Berther
committed
Merge branch 'master' of git://github.com/stefanheine/winston-daily-rotate-file into stefanheine-master
# Conflicts: # index.js
2 parents 8d949d0 + 7c2318f commit 9bd80b8

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
winston.add(require('winston-daily-rotate-file'), options)
1111
```
1212

13-
The DailyRotateFile transport can rotate files by minute, hour, day, month or year. In addition to the options accepted by the File transport, the Daily Rotate File Transport also accepts the following options:
13+
The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the File transport, the Daily Rotate File Transport also accepts the following options:
1414

15-
* __datePattern:__ A string representing the pattern to be used when appending the date to the filename (default '.yyyy-MM-dd'). 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.
16-
* __prepend:__ Defines if the rolling time of the log file should be prepended at the begging of the filename (default `false`)
15+
* __datePattern:__ A string representing the pattern to be used when appending the date to the filename (default 'yyyy-MM-dd'). 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.
16+
* __prepend:__ Defines if the rolling time of the log file should be prepended at the beginning of the filename (default 'false').
1717

1818
Valid meta characters in the datePattern are:
1919

@@ -27,6 +27,7 @@ Valid meta characters in the datePattern are:
2727
* __HH:__ The zero padded hour.
2828
* __m:__ The minute.
2929
* __mm:__ The zero padded minute.
30+
* __ddd:__ The weekday (Mon, Tue, ..., Sun).
3031

3132
*Metadata:* Logged via util.inspect(meta);
3233

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var Stream = require('stream').Stream;
99
var os = require('os');
1010
var winston = require('winston');
1111

12+
var weekday = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
13+
1214
//
1315
// ### function DailyRotateFile (options)
1416
// #### @options {Object} Options for this instance.
@@ -96,6 +98,7 @@ var DailyRotateFile = module.exports = function (options) {
9698
this._date = now.getUTCDate();
9799
this._hour = now.getUTCHours();
98100
this._minute = now.getUTCMinutes();
101+
this._weekday = weekday[now.getUTCDay()];
99102

100103
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhM])\1?/g;
101104
var pad = function (val, len) {
@@ -118,7 +121,8 @@ var DailyRotateFile = module.exports = function (options) {
118121
H: this._hour,
119122
HH: pad(this._hour),
120123
m: this._minute,
121-
mm: pad(this._minute)
124+
mm: pad(this._minute),
125+
ddd: this._weekday
122126
};
123127
return this.datePattern.replace(token, function ($0) {
124128
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
@@ -554,6 +558,7 @@ DailyRotateFile.prototype._createStream = function () {
554558
self._date = now.getUTCDate();
555559
self._hour = now.getUTCHours();
556560
self._minute = now.getUTCMinutes();
561+
self._weekday = weekday[now.getUTCDay()];
557562
self._created = 0;
558563
return checkFile(self._getFile());
559564
}

test/simple.tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ var transports = {
2424
'prepended file': new DailyRotateFile({
2525
filename: path.join(fixturesDir, 'testfilename.log'),
2626
prepend: true
27+
}),
28+
'weekday file': new DailyRotateFile({
29+
filename: path.join(fixturesDir, 'testfilename_weekday'),
30+
datePattern: '.ddd.log'
31+
}),
32+
'prepend weekday file': new DailyRotateFile({
33+
filename: path.join(fixturesDir, 'testfilename_prepend_weekday.log'),
34+
datePattern: 'ddd-',
35+
prepend: true
2736
})
2837
};
2938

0 commit comments

Comments
 (0)