Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #566 maxFiles doesn't seem to behave as expected #578

Merged
merged 3 commits into from
Mar 16, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ File.prototype._checkMaxFilesIncrementing = function (ext, basename, callback) {
}

oldest = this._created - this.maxFiles;
target = path.join(this.dirname, basename + (oldest === 0 ? oldest : '') + ext);
target = path.join(this.dirname, basename + (oldest !== 0 ? oldest : '') + ext);
fs.unlink(target, callback);
};

Expand Down
34 changes: 17 additions & 17 deletions test/transports/file-maxfiles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var maxfilesTransport = new winston.transports.File({
maxsize: 4096,
maxFiles: 3
});

vows.describe('winston/transports/file/maxfiles').addBatch({
"An instance of the File Transport": {
"when passed a valid filename": {
Expand All @@ -43,48 +43,48 @@ vows.describe('winston/transports/file/maxfiles').addBatch({
topic: function () {
var that = this,
created = 0;

function data(ch) {
return new Array(1018).join(String.fromCharCode(65 + ch));
};

function logKbytes(kbytes, txt) {
//
// With no timestamp and at the info level,
// winston adds exactly 7 characters:
// winston adds exactly 7 characters:
// [info](4)[ :](2)[\n](1)
//
for (var i = 0; i < kbytes; i++) {
maxfilesTransport.log('info', data(txt), null, function () { });
}
}

maxfilesTransport.on('logged', function () {
if (++created === 6) {
return that.callback();
}

logKbytes(4, created);
});

logKbytes(4, created);
},
"should be only 3 files called 5.log, 4.log and 3.log": function () {
for (var num = 0; num < 6; num++) {
var file = !num ? 'testmaxfiles.log' : 'testmaxfiles' + num + '.log',
fullpath = path.join(__dirname, '..', 'fixtures', 'logs', file);

// There should be no files with that name
if (num >= 0 && num < 3) {
return assert.throws(function () {
fs.statSync(file);
assert.throws(function () {
fs.statSync(fullpath);
}, Error);
}

// The other files should be exist
assert.doesNotThrow(function () {
fs.statSync(file);
}, Error);
} else {
// The other files should be exist
assert.doesNotThrow(function () {
fs.statSync(fullpath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: 2-space tabs here.

}, Error);
}
}
},
"should have the correct content": function () {
Expand All @@ -99,4 +99,4 @@ vows.describe('winston/transports/file/maxfiles').addBatch({
}
}
}
}).export(module);
}).export(module);