Skip to content

Commit

Permalink
fix issue winstonjs#1194 - where rotation of files isn't done when ta…
Browse files Browse the repository at this point in the history
…ilable is set to true
  • Loading branch information
ledbit committed Jul 25, 2018
1 parent cf424be commit 6c17bc4
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,20 +595,18 @@ module.exports = class File extends TransportStream {
// const isZipped = this.zippedArchive ? '.gz' : '';
const isZipped = this.zippedArchive ? '.gz' : '';
for (let x = this.maxFiles - 1; x > 0; x--) {
tasks.push(function (i) {
return cb => {
let fileName = `${basename}${(i - 1)}${ext}${isZipped}`;
const tmppath = path.join(this.dirname, fileName);

fs.exists(tmppath, exists => {
if (!exists) {
return cb(null);
}

fileName = `${basename}${i}${ext}${isZipped}`;
fs.rename(tmppath, path.join(this.dirname, fileName), cb);
});
};
tasks.push(function (i, cb) {
let fileName = `${basename}${(i - 1)}${ext}${isZipped}`;
const tmppath = path.join(this.dirname, fileName);

fs.exists(tmppath, exists => {
if (!exists) {
return cb(null);
}

fileName = `${basename}${i}${ext}${isZipped}`;
fs.rename(tmppath, path.join(this.dirname, fileName), cb);
});
}.bind(this, x));
}

Expand Down

0 comments on commit 6c17bc4

Please sign in to comment.