Reputation: 6809
I have small question to know whether log4js library is asynchronous. I tried to find the log4js document but no luck. I want to use this in my node js app's but before that i want to know is its asynchronous or not?
Upvotes: 3
Views: 2106
Reputation: 8635
Logger itself is asynchronous, but appender it is using might not.
For instance you are using the log4js logger with console
as appender.
Note that the console in node.js is synchronous since version 0.6.
Now running log function creates a LogEvent object and emits log
event:
Logger.prototype.log = function() {
var args = Array.prototype.slice.call(arguments)
, logLevel = levels.toLevel(args.shift())
, loggingEvent;
if (this.isLevelEnabled(logLevel)) {
loggingEvent = new LoggingEvent(this.category, logLevel, args, this);
this.emit("log", loggingEvent);
}
};
Now it is up to the event listener to decide whether it is async or not. Meaning that async or not purely depends on the appender implementation. You can see all the available appenders here.
file.js is async, while console and fileSync are synchronous.
Shortly, logger passes request to a writer, where it is synchronous or not depends on specifications of a writer. There are actually good reasons why console is synchronous.
Upvotes: 4