diff --git a/lib/appenders/fileSync.js b/lib/appenders/fileSync.js index 995ed78..071ea9e 100755 --- a/lib/appenders/fileSync.js +++ b/lib/appenders/fileSync.js @@ -51,19 +51,15 @@ function touchFile(file, options) { } class RollingFileSync { - constructor(filename, size, backups, options) { + constructor(filename, maxLogSize, backups, options) { debug('In RollingFileStream'); - function throwErrorIfArgumentsAreNotValid() { - if (!filename || !size || size <= 0) { - throw new Error('You must specify a filename and file size'); - } + if (maxLogSize < 0) { + throw new Error(`maxLogSize (${maxLogSize}) should be > 0`); } - throwErrorIfArgumentsAreNotValid(); - this.filename = filename; - this.size = size; + this.size = maxLogSize; this.backups = backups; this.options = options; this.currentSize = 0; diff --git a/test/tap/fileSyncAppender-test.js b/test/tap/fileSyncAppender-test.js index c7f0190..f6a2eb2 100644 --- a/test/tap/fileSyncAppender-test.js +++ b/test/tap/fileSyncAppender-test.js @@ -61,6 +61,28 @@ test("log4js fileSyncAppender", batch => { t.end(); }); + batch.test("should give error if invalid maxLogSize", async t => { + const maxLogSize = -1; + const expectedError = new Error(`maxLogSize (${maxLogSize}) should be > 0`); + t.throws( + () => + log4js.configure({ + appenders: { + file: { + type: "fileSync", + filename: path.join(__dirname, "fa-invalidMaxFileSize-sync-test.log"), + maxLogSize: -1 + } + }, + categories: { + default: { appenders: ["file"], level: "debug" } + } + }), + expectedError + ); + t.end(); + }); + batch.test("with a max file size and no backups", t => { const testFile = path.join(__dirname, "/fa-maxFileSize-sync-test.log"); const logger = log4js.getLogger("max-file-size");