From 826adf031d8d1d46e40647c4ef8d31f876aacd1f Mon Sep 17 00:00:00 2001 From: myAlapi Date: Sat, 24 Jun 2023 13:48:34 +0530 Subject: [PATCH 1/9] Test for file Transport option rotationFormat --- .../transports/file-rotationFormat.test.js | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/unit/winston/transports/file-rotationFormat.test.js diff --git a/test/unit/winston/transports/file-rotationFormat.test.js b/test/unit/winston/transports/file-rotationFormat.test.js new file mode 100644 index 000000000..007698bc6 --- /dev/null +++ b/test/unit/winston/transports/file-rotationFormat.test.js @@ -0,0 +1,141 @@ +'use strict'; + +const path = require('path'); +const winston = require('../../../../lib/winston'); +const helpers = require('../../../helpers'); +const fs = require('fs'); +const { MESSAGE } = require('triple-beam'); +const split = require('split2'); +const assume = require('assume'); +const rimraf = require('rimraf'); +const testFileFixturesPath = path.join( + __dirname, + '..', + '..', + '..', + 'fixtures', + 'file' +); + +// +// Remove all log fixtures +// +function removeFixtures(done) { + rimraf(path.join(testFileFixturesPath, 'rotation*'), done); +} + +// Validate Filename according to rotation +function isCorrectFormat(filename) { + let time = filename.split('rotation')[1].split('.')[0]; + console.log(time); + return new Date(time).getTime() > 0; +} + +describe.only('winston/transports/file/rotationFormat', function () { + this.timeout(10000); + + let testDone = false; + before(removeFixtures); + after(done => { + testDone = true; + removeFixtures(done); + }); + + it('should create multiple files correctly with rotation Function', function (done) { + const fillWith = ['a', 'b', 'c', 'd', 'e']; + const rotationTransport = new winston.transports.File({ + level: 'info', + format: winston.format.printf(info => info.message), + filename: path.join(testFileFixturesPath, 'rotation.log'), + maxsize: 4096, + rotationFormat: () => { + return new Date().getTime(); + } + }); + + // + // Have to wait for `fs.stats` to be done in `rotationTransport.open()`. + // Otherwise the rotationTransport._dest is undefined. See https://github.com/winstonjs/winston/issues/1174 + // + + // + // Setup a list of files which we will later stat. + // + const files = []; + + // + // Assets all the files have been created with the + // correct filesize + // + function assumeFilesCreated() { + files.map(function (file, i) { + console.log(i, file); + let stats; + try { + stats = fs.statSync(file); + } catch (ex) { + assume(stats).is.an( + 'object', + `${file} failed to open: ${ex.message}` + ); + } + + const text = fs.readFileSync(file, 'utf8'); + assume(text[0]).equals(fillWith[i]); + assume(isCorrectFormat(file)); + // Either 4096 on Unix or 4100 on Windows + // because of the eol. + if (process.platform === 'win32') { + assume(stats.size).equals(4100); + } else { + assume(stats.size).equals(4096); + } + }); + + done(); + } + + // + // Log the specified kbytes to the transport + // + function logKbytes(kbytes) { + console.log('Loging kbytes'); + // + // Shift the next fill char off the array then push it back + // to rotate the chars. + // + const filler = fillWith.shift(); + fillWith.push(filler); + console.log(filler, fillWith); + + // + // + // To not make each file not fail the assertion of the filesize we can + // make the array 1023 characters long. + // + const kbStr = Array(1023).fill(filler).join(''); + + // + // With printf format that displays the message only + // winston adds exactly 0 characters. + // + for (var i = 0; i < kbytes; i++) { + rotationTransport.log({ level: 'info', [MESSAGE]: kbStr }); + } + } + + rotationTransport.on('open', function (file) { + console.log('Opening Transport'); + + if (testDone) return; // ignore future notifications + const match = file.match(/(\d+)\.log$/); + const count = match ? match[1] : 0; + if (files.length === 5) { + return assumeFilesCreated(); + } + + files.push(file); + setImmediate(() => logKbytes(4)); + }); + }); +}); From 1ff9b1baaa567027659a79b1e7bc9a7760f96823 Mon Sep 17 00:00:00 2001 From: myAlapi Date: Sat, 24 Jun 2023 14:04:04 +0530 Subject: [PATCH 2/9] Test for file Transport option rotationFormat --- test/unit/winston/transports/file-rotationFormat.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/winston/transports/file-rotationFormat.test.js b/test/unit/winston/transports/file-rotationFormat.test.js index 007698bc6..77dafc7d5 100644 --- a/test/unit/winston/transports/file-rotationFormat.test.js +++ b/test/unit/winston/transports/file-rotationFormat.test.js @@ -31,7 +31,7 @@ function isCorrectFormat(filename) { return new Date(time).getTime() > 0; } -describe.only('winston/transports/file/rotationFormat', function () { +describe('winston/transports/file/rotationFormat', function () { this.timeout(10000); let testDone = false; From 3d162a4049cdd735e5648ad4eca8d27916089828 Mon Sep 17 00:00:00 2001 From: myAlapi Date: Tue, 27 Jun 2023 22:00:59 +0530 Subject: [PATCH 3/9] Added Lazy option in file transport --- docs/transports.md | 1 + lib/winston/transports/file.js | 55 +++++++++--- .../winston/transports/00-file-stress.test.js | 43 ++++++++++ .../transports/01-file-maxsize.test.js | 85 ++++++++++++++++++- .../unit/winston/transports/file-lazy.test.js | 61 +++++++++++++ .../transports/file-rotationFormat.test.js | 1 - 6 files changed, 231 insertions(+), 15 deletions(-) create mode 100644 test/unit/winston/transports/file-lazy.test.js diff --git a/docs/transports.md b/docs/transports.md index c5dc8eafd..3ad2466d1 100644 --- a/docs/transports.md +++ b/docs/transports.md @@ -102,6 +102,7 @@ looking for daily log rotation see [DailyRotateFile](#dailyrotatefile-transport) * __level:__ Level of messages that this transport should log (default: level set on parent logger). * __silent:__ Boolean flag indicating whether to suppress output (default false). * __eol:__ Line-ending character to use. (default: `os.EOL`). +* __lazy:__ If true, log files will be created on demand, not at the initialization time. * __filename:__ The filename of the logfile to write output to. * __maxsize:__ Max size in bytes of the logfile, if the size is exceeded then a new file is created, a counter will become a suffix of the log file. * __maxFiles:__ Limit the number of files created when the size of the logfile is exceeded. diff --git a/lib/winston/transports/file.js b/lib/winston/transports/file.js index 49edd8b13..8347f88c9 100644 --- a/lib/winston/transports/file.js +++ b/lib/winston/transports/file.js @@ -79,6 +79,7 @@ module.exports = class File extends TransportStream { this.maxFiles = options.maxFiles || null; this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL; this.tailable = options.tailable || false; + this.lazy = options.lazy || false; // Internal state variables representing the number of files this instance // has created and the current size (in bytes) of the current logfile. @@ -88,9 +89,10 @@ module.exports = class File extends TransportStream { this._drain = false; this._opening = false; this._ending = false; + this._fileExist = false; if (this.dirname) this._createLogDirIfNotExist(this.dirname); - this.open(); + if (!this.lazy) this.open(); } finishIfEnding() { @@ -107,7 +109,6 @@ module.exports = class File extends TransportStream { } } - /** * Core logging method exposed to Winston. Metadata is optional. * @param {Object} info - TODO: add param description. @@ -123,6 +124,32 @@ module.exports = class File extends TransportStream { return true; } + if (this.lazy) { + if (!this._fileExist) { + if (!this._opening) { + this.open(); + } + this.once('open', () => { + this._fileExist = true; + this.log(info, callback); + return; + }); + return; + } + if (this._needsNewFile(this._pendingSize)) { + this._dest.once('close', () => { + if (!this._opening) { + this.open(); + } + this.once('open', () => { + this.log(info, callback); + return; + }); + return; + }); + return; + } + } // Output stream buffer is full and has asked us to wait for the drain event if (this._drain) { this._stream.once('drain', () => { @@ -169,6 +196,10 @@ module.exports = class File extends TransportStream { if (!this._needsNewFile()) { return; } + if (this.lazy) { + this._endStream(); + return; + } // End the current stream, ensure it flushes and create a new one. // This could potentially be optimized to not run a stat call but its @@ -616,8 +647,8 @@ module.exports = class File extends TransportStream { // combined with max files because the set of files to unlink is never // stored. const target = !this.tailable && this._created - ? `${basename}${isRotation}${ext}` - : `${basename}${ext}`; + ? `${basename}${isRotation}${ext}` + : `${basename}${ext}`; return this.zippedArchive && !this.tailable ? `${target}.gz` @@ -669,16 +700,16 @@ module.exports = class File extends TransportStream { for (let x = this.maxFiles - 1; x > 1; x--) { tasks.push(function (i, cb) { let fileName = `${basename}${(i - 1)}${ext}${isZipped}`; - const tmppath = path.join(this.dirname, fileName); + const tmppath = path.join(this.dirname, fileName); - fs.exists(tmppath, exists => { - if (!exists) { - return cb(null); - } + fs.exists(tmppath, exists => { + if (!exists) { + return cb(null); + } - fileName = `${basename}${i}${ext}${isZipped}`; - fs.rename(tmppath, path.join(this.dirname, fileName), cb); - }); + fileName = `${basename}${i}${ext}${isZipped}`; + fs.rename(tmppath, path.join(this.dirname, fileName), cb); + }); }.bind(this, x)); } diff --git a/test/unit/winston/transports/00-file-stress.test.js b/test/unit/winston/transports/00-file-stress.test.js index 55cae623d..46fe59768 100644 --- a/test/unit/winston/transports/00-file-stress.test.js +++ b/test/unit/winston/transports/00-file-stress.test.js @@ -150,4 +150,47 @@ describe('File (stress)', function () { }); }, 10000); }); + + it('should handle a high volume of writes with lazy option enabled', function (done) { + const logger = winston.createLogger({ + transports: [ + new winston.transports.File({ + filename: fileStressLogFile, + lazy: true + }) + ] + }); + + const counters = { + write: 0, + read: 0 + }; + + const interval = setInterval(function () { + logger.info(++counters.write); + }, 0); + + setTimeout(function () { + clearInterval(interval); + + helpers + .tryRead(fileStressLogFile) + .on('error', function (err) { + assume(err).false(); + logger.close(); + done(); + }) + .pipe(split()) + .on('data', function (d) { + const json = JSON.parse(d); + assume(json.level).equal('info'); + assume(json.message).equal(++counters.read); + }) + .on('end', function () { + assume(counters.write).equal(counters.read); + logger.close(); + done(); + }); + }, 10000); + }); }); diff --git a/test/unit/winston/transports/01-file-maxsize.test.js b/test/unit/winston/transports/01-file-maxsize.test.js index 01ca88076..736c3992a 100644 --- a/test/unit/winston/transports/01-file-maxsize.test.js +++ b/test/unit/winston/transports/01-file-maxsize.test.js @@ -25,8 +25,8 @@ describe('File (maxsize)', function () { this.timeout(10000); let testDone = false; - before(removeFixtures); - after(done => { + this.beforeEach(removeFixtures); + this.afterEach(done => { testDone = true; removeFixtures(done); }); @@ -119,4 +119,85 @@ describe('File (maxsize)', function () { setImmediate(() => logKbytes(4)); }); }); + + describe('With lazy option enabled', () => { + it('should not create extra file', function (done) { + const fillWith = ['a', 'b', 'c', 'd', 'e']; + const lazyTransport = new winston.transports.File({ + format: winston.format.printf(info => info.message), + filename: path.join(testLogFixturesPath, 'testmaxsize.log'), + maxsize: 3072, + lazy: true + }); + const logger = winston.createLogger({ + transports: [lazyTransport] + }); + // + // Setup a list of files which we will later stat. + // + const files = []; + + // + // Assets all the files have been created with the + // correct filesize + // + function assumeFilesCreated() { + assume(files.length).equals(fillWith.length); + files.map(function (file, i) { + let stats; + try { + stats = fs.statSync(file); + } catch (ex) { + assume(stats).is.an( + 'object', + `${file} failed to open: ${ex.message}` + ); + } + + const text = fs.readFileSync(file, 'utf8'); + assume(text[0]).equals(fillWith[i]); + // Either 4096 on Unix or 4100 on Windows + // because of the eol. + if (process.platform === 'win32') { + assume(stats.size).equals(3075); + } else { + assume(stats.size).equals(3072); + } + }); + done(); + } + + // + // Log the specified kbytes to the transport + // + function logKbytes(kbytes) { + // + // Shift the next fill char off the array then push it back + // to rotate the chars. + // + const filler = fillWith.shift(); + fillWith.push(filler); + + // + // + // To not make each file not fail the assertion of the filesize we can + // make the array 1023 characters long. + // + const kbStr = Array(1023).fill(filler).join(''); + for (var i = 0; i < kbytes; i++) { + logger.log({ level: 'info', message: kbStr }); + } + } + for (var i = 0; i < fillWith.length; i++) { + setImmediate(()=>{logKbytes(3)}); + } + setTimeout(function () { + assumeFilesCreated(); + }, 1000); + + lazyTransport.on('open', file => { + files.push(file); + }); + }); + }); }); diff --git a/test/unit/winston/transports/file-lazy.test.js b/test/unit/winston/transports/file-lazy.test.js new file mode 100644 index 000000000..d5516b865 --- /dev/null +++ b/test/unit/winston/transports/file-lazy.test.js @@ -0,0 +1,61 @@ +'use strict'; + +const path = require('path'); +const winston = require('../../../../lib/winston'); +const helpers = require('../../../helpers'); +const fs = require('fs'); +const { MESSAGE } = require('triple-beam'); +const split = require('split2'); +const assume = require('assume'); + +function noop() {} + +describe('Lazy Option Test', function () { + this.timeout(10 * 1000); + var logPath = path.join( + __dirname, + '..', + '..', + '..', + 'fixtures', + 'file', + 'lazy.log' + ); + + beforeEach(function () { + try { + fs.unlinkSync(logPath); + } catch (ex) { + if (ex && ex.code !== 'ENOENT') { + return done(ex); + } + } + }); + + it('should not create a log file before receiving any logs', function (done) { + var transport = new winston.transports.File({ + filename: logPath, + lazy: true + }); + + setTimeout(function () { + assume(fs.existsSync(logPath)).false(); + done(); + }, 0); + }); + it('should create a log file after receiving log', function (done) { + var transport = new winston.transports.File({ + filename: logPath, + lazy: true + }); + + var info = { [MESSAGE]: 'this is my log message' }; + + transport.log(info, noop); + + setTimeout(function () { + assume(fs.existsSync(logPath)); + done(); + }, 0); + }); +}); diff --git a/test/unit/winston/transports/file-rotationFormat.test.js b/test/unit/winston/transports/file-rotationFormat.test.js index 77dafc7d5..a5a8dff46 100644 --- a/test/unit/winston/transports/file-rotationFormat.test.js +++ b/test/unit/winston/transports/file-rotationFormat.test.js @@ -106,7 +106,6 @@ describe('winston/transports/file/rotationFormat', function () { // const filler = fillWith.shift(); fillWith.push(filler); - console.log(filler, fillWith); // // From d863e565569f4cf6a5e372fe6372b43aeb0f313d Mon Sep 17 00:00:00 2001 From: myAlapi Date: Wed, 28 Jun 2023 16:14:33 +0530 Subject: [PATCH 4/9] Lint and test --- lib/winston/transports/file.js | 60 +++++++++---------- .../transports/01-file-maxsize.test.js | 26 +++++--- .../transports/file-rotationFormat.test.js | 4 -- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/lib/winston/transports/file.js b/lib/winston/transports/file.js index 8347f88c9..b5801038b 100644 --- a/lib/winston/transports/file.js +++ b/lib/winston/transports/file.js @@ -115,7 +115,7 @@ module.exports = class File extends TransportStream { * @param {Function} callback - TODO: add param description. * @returns {undefined} */ - log(info, callback = () => {}) { + log(info, callback = () => { }) { // Remark: (jcrugzz) What is necessary about this callback(null, true) now // when thinking about 3.x? Should silent be handled in the base // TransportStream _write method? @@ -124,6 +124,22 @@ module.exports = class File extends TransportStream { return true; } + + // Output stream buffer is full and has asked us to wait for the drain event + if (this._drain) { + this._stream.once('drain', () => { + this._drain = false; + this.log(info, callback); + }); + return; + } + if (this._rotate) { + this._stream.once('rotate', () => { + this._rotate = false; + this.log(info, callback); + }); + return; + } if (this.lazy) { if (!this._fileExist) { if (!this._opening) { @@ -150,21 +166,6 @@ module.exports = class File extends TransportStream { return; } } - // Output stream buffer is full and has asked us to wait for the drain event - if (this._drain) { - this._stream.once('drain', () => { - this._drain = false; - this.log(info, callback); - }); - return; - } - if (this._rotate) { - this._stream.once('rotate', () => { - this._rotate = false; - this.log(info, callback); - }); - return; - } // Grab the raw string and append the expected EOL. const output = `${info[MESSAGE]}${this.eol}`; @@ -197,7 +198,7 @@ module.exports = class File extends TransportStream { return; } if (this.lazy) { - this._endStream(); + this._endStream(() => {this.emit('fileclosed')}); return; } @@ -539,7 +540,6 @@ module.exports = class File extends TransportStream { _cleanupStream(stream) { stream.removeListener('error', this._onError); stream.destroy(); - return stream; } @@ -557,7 +557,7 @@ module.exports = class File extends TransportStream { * @param {function} callback - Callback for when the current file has closed. * @private */ - _endStream(callback = () => {}) { + _endStream(callback = () => { }) { if (this._dest) { this._stream.unpipe(this._dest); this._dest.end(() => { @@ -573,7 +573,7 @@ module.exports = class File extends TransportStream { * Returns the WritableStream for the active file on this instance. If we * should gzip the file then a zlib stream is returned. * - * @param {ReadableStream} source – PassThrough to pipe to the file when open. + * @param {ReadableStream} source –PassThrough to pipe to the file when open. * @returns {WritableStream} Stream that writes to disk for the active file. */ _createStream(source) { @@ -647,8 +647,8 @@ module.exports = class File extends TransportStream { // combined with max files because the set of files to unlink is never // stored. const target = !this.tailable && this._created - ? `${basename}${isRotation}${ext}` - : `${basename}${ext}`; + ? `${basename}${isRotation}${ext}` + : `${basename}${ext}`; return this.zippedArchive && !this.tailable ? `${target}.gz` @@ -700,16 +700,16 @@ module.exports = class File extends TransportStream { for (let x = this.maxFiles - 1; x > 1; x--) { tasks.push(function (i, cb) { let fileName = `${basename}${(i - 1)}${ext}${isZipped}`; - const tmppath = path.join(this.dirname, fileName); + const tmppath = path.join(this.dirname, fileName); - fs.exists(tmppath, exists => { - if (!exists) { - return cb(null); - } + fs.exists(tmppath, exists => { + if (!exists) { + return cb(null); + } - fileName = `${basename}${i}${ext}${isZipped}`; - fs.rename(tmppath, path.join(this.dirname, fileName), cb); - }); + fileName = `${basename}${i}${ext}${isZipped}`; + fs.rename(tmppath, path.join(this.dirname, fileName), cb); + }); }.bind(this, x)); } diff --git a/test/unit/winston/transports/01-file-maxsize.test.js b/test/unit/winston/transports/01-file-maxsize.test.js index 736c3992a..3f3dbde1f 100644 --- a/test/unit/winston/transports/01-file-maxsize.test.js +++ b/test/unit/winston/transports/01-file-maxsize.test.js @@ -121,7 +121,7 @@ describe('File (maxsize)', function () { }); describe('With lazy option enabled', () => { - it('should not create extra file', function (done) { + it.only('should not create extra file', function (done) { const fillWith = ['a', 'b', 'c', 'd', 'e']; const lazyTransport = new winston.transports.File({ format: winston.format.printf(info => info.message), @@ -138,8 +138,8 @@ describe('File (maxsize)', function () { const files = []; // - // Assets all the files have been created with the - // correct filesize + // Assets the no of files and all the files have been created with the + // correct filesize // function assumeFilesCreated() { assume(files.length).equals(fillWith.length); @@ -188,13 +188,23 @@ describe('File (maxsize)', function () { logger.log({ level: 'info', message: kbStr }); } } - for (var i = 0; i < fillWith.length; i++) { - setImmediate(()=>{logKbytes(3)}); - } - setTimeout(function () { + + // Initial Log + let count =1; + logKbytes(3); + + //Listent to file close event called when the file is closed + lazyTransport.on('fileclosed', ()=>{ + if(count === fillWith.length){ assumeFilesCreated(); - }, 1000); + return; + } + count+=1; + setImmediate(()=>{logKbytes(3);}); + }) + + //Listent to file open event called when the file is opened lazyTransport.on('open', file => { files.push(file); }); diff --git a/test/unit/winston/transports/file-rotationFormat.test.js b/test/unit/winston/transports/file-rotationFormat.test.js index a5a8dff46..0626cdc7b 100644 --- a/test/unit/winston/transports/file-rotationFormat.test.js +++ b/test/unit/winston/transports/file-rotationFormat.test.js @@ -27,7 +27,6 @@ function removeFixtures(done) { // Validate Filename according to rotation function isCorrectFormat(filename) { let time = filename.split('rotation')[1].split('.')[0]; - console.log(time); return new Date(time).getTime() > 0; } @@ -69,7 +68,6 @@ describe('winston/transports/file/rotationFormat', function () { // function assumeFilesCreated() { files.map(function (file, i) { - console.log(i, file); let stats; try { stats = fs.statSync(file); @@ -99,7 +97,6 @@ describe('winston/transports/file/rotationFormat', function () { // Log the specified kbytes to the transport // function logKbytes(kbytes) { - console.log('Loging kbytes'); // // Shift the next fill char off the array then push it back // to rotate the chars. @@ -124,7 +121,6 @@ describe('winston/transports/file/rotationFormat', function () { } rotationTransport.on('open', function (file) { - console.log('Opening Transport'); if (testDone) return; // ignore future notifications const match = file.match(/(\d+)\.log$/); From c587108c3786cb036142fcef9609c1d6fb928444 Mon Sep 17 00:00:00 2001 From: myAlapi Date: Wed, 28 Jun 2023 16:16:41 +0530 Subject: [PATCH 5/9] removed only statement --- test/unit/winston/transports/01-file-maxsize.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/winston/transports/01-file-maxsize.test.js b/test/unit/winston/transports/01-file-maxsize.test.js index 3f3dbde1f..4e2510d15 100644 --- a/test/unit/winston/transports/01-file-maxsize.test.js +++ b/test/unit/winston/transports/01-file-maxsize.test.js @@ -121,7 +121,7 @@ describe('File (maxsize)', function () { }); describe('With lazy option enabled', () => { - it.only('should not create extra file', function (done) { + it('should not create extra file', function (done) { const fillWith = ['a', 'b', 'c', 'd', 'e']; const lazyTransport = new winston.transports.File({ format: winston.format.printf(info => info.message), From 6ab1c03db90a1499cecb66572dee58ee31edbbdd Mon Sep 17 00:00:00 2001 From: Pulkit Aggarwal <82268257+Pulkit0729@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:26:13 +0530 Subject: [PATCH 6/9] Update test/unit/winston/transports/01-file-maxsize.test.js Co-authored-by: David Hyde --- test/unit/winston/transports/01-file-maxsize.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/winston/transports/01-file-maxsize.test.js b/test/unit/winston/transports/01-file-maxsize.test.js index 4e2510d15..192f82887 100644 --- a/test/unit/winston/transports/01-file-maxsize.test.js +++ b/test/unit/winston/transports/01-file-maxsize.test.js @@ -193,7 +193,7 @@ describe('File (maxsize)', function () { let count =1; logKbytes(3); - //Listent to file close event called when the file is closed + // Listen to file close event called when the file is closed lazyTransport.on('fileclosed', ()=>{ if(count === fillWith.length){ assumeFilesCreated(); From b4f7af0e416110d892dca4e6d0fe5759ae1c80b4 Mon Sep 17 00:00:00 2001 From: Pulkit Aggarwal <82268257+Pulkit0729@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:26:23 +0530 Subject: [PATCH 7/9] Update test/unit/winston/transports/01-file-maxsize.test.js Co-authored-by: David Hyde --- test/unit/winston/transports/01-file-maxsize.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/unit/winston/transports/01-file-maxsize.test.js b/test/unit/winston/transports/01-file-maxsize.test.js index 192f82887..8f2db41ec 100644 --- a/test/unit/winston/transports/01-file-maxsize.test.js +++ b/test/unit/winston/transports/01-file-maxsize.test.js @@ -195,12 +195,11 @@ describe('File (maxsize)', function () { // Listen to file close event called when the file is closed lazyTransport.on('fileclosed', ()=>{ - if(count === fillWith.length){ - assumeFilesCreated(); - + if (count === fillWith.length) { + assumeFilesCreated(); return; } - count+=1; + count += 1; setImmediate(()=>{logKbytes(3);}); }) From 0d5e2836c0c5a4e26cfaabd2ba5ebac657c850f1 Mon Sep 17 00:00:00 2001 From: Pulkit0729 Date: Wed, 19 Jul 2023 20:15:53 +0530 Subject: [PATCH 8/9] Added lazy in FileTransportOptions types --- lib/winston/transports/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/winston/transports/index.d.ts b/lib/winston/transports/index.d.ts index b8b6c62b8..a5671354c 100644 --- a/lib/winston/transports/index.d.ts +++ b/lib/winston/transports/index.d.ts @@ -34,6 +34,7 @@ declare namespace winston { maxFiles?: number; eol?: string; tailable?: boolean; + lazy?: boolean; } interface FileTransportInstance extends Transport { From 6f65e62b92b3ce80be30ce13ed3c1772d513eae8 Mon Sep 17 00:00:00 2001 From: Pulkit0729 Date: Wed, 19 Jul 2023 20:20:51 +0530 Subject: [PATCH 9/9] Added lazy type in FileTransportInstance --- lib/winston/transports/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/winston/transports/index.d.ts b/lib/winston/transports/index.d.ts index a5671354c..c3eb45045 100644 --- a/lib/winston/transports/index.d.ts +++ b/lib/winston/transports/index.d.ts @@ -48,6 +48,7 @@ declare namespace winston { maxFiles: number | null; eol: string; tailable: boolean; + lazy: boolean; new(options?: FileTransportOptions): FileTransportInstance; }