simple-node-logger
simple-node-logger copied to clipboard
log files not closed automatically
My configuration:
options = {
logFilePath: filePath,
timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
},
log = SimpleNodeLogger.createSimpleLogger(options);
When check with open file using lsof
, the log file still open. if i shutdown my app the the files are closed.but if the app run forever it will open file,each time .Hence slowly it's eat my memory. Please guide me solve this issue
rolling logger is probably what you want; the active file gets closed when it rolls.
It seems to me that FileAppender
opens new stream on every call, eg:
const SimpleLogger = require('simple-node-logger');
for(let i = 0; i< 10; i++) {
let manager = new SimpleLogger();
manager.createFileAppender( { logFilePath:filename } );
let log1 = manager.createLogger( 'CategoryOne', 'trace' );
}
Or a more frequent situation: create loger for the same log file, in different js files.
@darrylwest I think FileAppender
should use the global writer
instance, eg:
let writerInstances = ()
//...
const openWriter = function() {
if (!writer) {
const file = path.normalize( logFilePath );
if(writerInstances[file]) {
writer = writerInstances[file]
} else {
const opts = {
flags:'a',
encoding:'utf8'
};
writer = writerInstances[file] =fs.createWriteStream( file, opts );
}
}
};