Skip to content

Commit fd3e85f

Browse files
author
Matt Berther
committed
resolving #44 and reverting to default filename concatenation unless default datePattern/prepend:true option is used
1 parent bc21c5a commit fd3e85f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var DailyRotateFile = module.exports = function (options) {
6969
this.prettyPrint = options.prettyPrint || false;
7070
this.showLevel = options.showLevel === undefined ? true : options.showLevel;
7171
this.timestamp = options.timestamp ? options.timestamp : true;
72-
this.datePattern = options.datePattern ? options.datePattern : 'yyyy-MM-dd';
72+
this.datePattern = options.datePattern ? options.datePattern : '.yyyy-MM-dd';
7373
this.depth = options.depth || null;
7474
this.eol = options.eol || os.EOL;
7575
this.maxRetries = options.maxRetries || 2;
@@ -598,17 +598,18 @@ DailyRotateFile.prototype._getFile = function (inc) {
598598
// Returns the log filename depending on `this.prepend` option value
599599
//
600600
DailyRotateFile.prototype._getFilename = function () {
601-
if (this.datePattern.substring(0, 1) === '.') {
602-
this.datePattern = this.datePattern.substring(1);
603-
}
604-
605601
var formattedDate = this.getFormattedDate();
606602

607603
if (this.prepend) {
608-
return [formattedDate, this._basename].join('.');
604+
if (this.datePattern === '.yyyy-MM-dd') {
605+
this.datePattern = 'yyyy-MM-dd.';
606+
formattedDate = this.getFormattedDate();
607+
}
608+
609+
return formattedDate + this._basename;
609610
}
610611

611-
return [this._basename, formattedDate].join('.');
612+
return this._basename + formattedDate;
612613
};
613614

614615
//

test/simple.tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ describe('winston/transports/daily-rotate-file', function () {
6161
expect(transport._getFilename()).to.equal('prepend-false.log.' + now);
6262
});
6363

64+
it('should not add leading dot if one is not provided with datePattern', function () {
65+
var now = moment().format('YYYY-MM-DD');
66+
var transport = new DailyRotateFile({
67+
filename: path.join(fixturesDir, 'log'),
68+
datePattern: '-yyyy-MM-dd.log'
69+
});
70+
71+
expect(transport._getFilename()).to.equal('log-' + now + '.log');
72+
});
73+
6474
it('should remove leading dot if one is provided with datePattern when prepend option is true', function () {
6575
var now = moment().format('YYYY-MM-DD');
6676
var transport = new DailyRotateFile({

0 commit comments

Comments
 (0)