simple-node-logger icon indicating copy to clipboard operation
simple-node-logger copied to clipboard

logger does not print anything if the process exits

Open jkryl opened this issue 5 years ago • 2 comments

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 🙃

jkryl avatar Apr 30 '19 12:04 jkryl

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.

theblindprophet avatar Jun 04 '19 13:06 theblindprophet

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...

Goro2030 avatar Sep 22 '19 06:09 Goro2030