Skip to content

Commit b626d08

Browse files
author
Matt Berther
committed
#71 updating logic to determine archive creation
1 parent b24c166 commit b626d08

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ DailyRotateFile.prototype.open = function (callback) {
445445
callback(true);
446446
return this._createStream();
447447
}
448-
this._archive = this.zippedArchive ? this._stream.path : false;
448+
449449
//
450450
// Otherwise we have a valid (and ready) stream.
451451
//
@@ -519,13 +519,14 @@ DailyRotateFile.prototype._createStream = function () {
519519

520520
(function checkFile(target) {
521521
var fullname = path.join(self.dirname, target);
522-
523522
//
524523
// Creates the `WriteStream` and then flushes any
525524
// buffered messages.
526525
//
527526
function createAndFlush(size) {
528527
if (self._stream) {
528+
self._archive = self.zippedArchive ? self._stream.path : false;
529+
529530
self._stream.end();
530531
self._stream.destroySoon();
531532
}

test/simple.tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,35 @@ describe('winston/transports/daily-rotate-file', function () {
686686
tk.reset();
687687
});
688688

689+
it('should compress logfile even if there is only one log message', function (done) {
690+
var self = this;
691+
692+
transport.log('error', 'test message', {}, function (err) {
693+
if (err) {
694+
done(err);
695+
}
696+
697+
var filesCreated = fs.readdirSync(rotationLogPath);
698+
expect(filesCreated.length).to.eql(1);
699+
expect(filesCreated).to.include(pattern.oldfile);
700+
self.time = new Date(pattern.end);
701+
tk.travel(self.time);
702+
transport.log('error', '2nd test message', {}, function (err) {
703+
if (err) {
704+
done(err);
705+
}
706+
707+
filesCreated = fs.readdirSync(rotationLogPath);
708+
expect(filesCreated.length).to.eql(2);
709+
expect(filesCreated).to.include(pattern.newfile);
710+
expect(filesCreated).to.include(pattern.oldfile + '.gz');
711+
transport.close();
712+
713+
done();
714+
});
715+
});
716+
});
717+
689718
it('should compress logfile without adding count to file extension if there are no files with the same name', function (done) {
690719
var self = this;
691720

0 commit comments

Comments
 (0)