Skip to content

Commit

Permalink
#71 updating logic to determine archive creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Berther committed Mar 3, 2017
1 parent b24c166 commit b626d08
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ DailyRotateFile.prototype.open = function (callback) {
callback(true);
return this._createStream();
}
this._archive = this.zippedArchive ? this._stream.path : false;

//
// Otherwise we have a valid (and ready) stream.
//
Expand Down Expand Up @@ -519,13 +519,14 @@ DailyRotateFile.prototype._createStream = function () {

(function checkFile(target) {
var fullname = path.join(self.dirname, target);

//
// Creates the `WriteStream` and then flushes any
// buffered messages.
//
function createAndFlush(size) {
if (self._stream) {
self._archive = self.zippedArchive ? self._stream.path : false;

self._stream.end();
self._stream.destroySoon();
}
Expand Down
29 changes: 29 additions & 0 deletions test/simple.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,35 @@ describe('winston/transports/daily-rotate-file', function () {
tk.reset();
});

it('should compress logfile even if there is only one log message', function (done) {
var self = this;

transport.log('error', 'test message', {}, function (err) {
if (err) {
done(err);
}

var filesCreated = fs.readdirSync(rotationLogPath);
expect(filesCreated.length).to.eql(1);
expect(filesCreated).to.include(pattern.oldfile);
self.time = new Date(pattern.end);
tk.travel(self.time);
transport.log('error', '2nd test message', {}, function (err) {
if (err) {
done(err);
}

filesCreated = fs.readdirSync(rotationLogPath);
expect(filesCreated.length).to.eql(2);
expect(filesCreated).to.include(pattern.newfile);
expect(filesCreated).to.include(pattern.oldfile + '.gz');
transport.close();

done();
});
});
});

it('should compress logfile without adding count to file extension if there are no files with the same name', function (done) {
var self = this;

Expand Down

0 comments on commit b626d08

Please sign in to comment.