simple-node-logger
simple-node-logger copied to clipboard
logger does not print anything if the process exits
I gave this logger module a try as I wanted to use a simple alternative to winston, but this logger is close to being useless. The fundamental flaw is that it prints the messages to the console in asynchronous callback. So if the program exits at some point then all messages logged in the same synchronous context are lost and never printed because the async callback which does the actual logging does not get a chance to run. For people who use it in long running processes which never throw exceptions or crash, it is probably ok 🙃
Second this. Not entirely sure but it looks like in Logger.js
the log entry is being returned before the entry is actually complete:
this.log = function(level, msg) {
const entry = logger.createEntry( level, msg );
process.nextTick(function() {
// write the message to the appenders...
appenders.forEach(function(appender) {
appender.write( entry );
});
if (level === 'error' && typeof(errorEventName) === 'string' || typeof(errorEventName) === String) {
process.emit(errorEventName, entry);
}
});
return entry;
};
For now, having to provide a timeout before exiting my script.
I second this ... I'm trying this in a NODE program, that writes a lot continuously, and I need to make sure that the log is being written to disk synchronously to continue...