-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Lazy option to file transport (#2317)
* Test for file Transport option rotationFormat * Test for file Transport option rotationFormat * Added Lazy option in file transport * Lint and test * removed only statement * Update test/unit/winston/transports/01-file-maxsize.test.js Co-authored-by: David Hyde <DABH@users.noreply.github.com> * Update test/unit/winston/transports/01-file-maxsize.test.js Co-authored-by: David Hyde <DABH@users.noreply.github.com> --------- Co-authored-by: myAlapi <myalapi2022@gmail.com> Co-authored-by: David Hyde <DABH@users.noreply.github.com>
- Loading branch information
1 parent
de2e887
commit f7e7f2f
Showing
6 changed files
with
370 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
Oops, something went wrong.