I am developing a logging framework using winston in nodejs , I had check that winston using Async module , but I need to verify whether it is truly Async nature or not.
Please suggest.
I have no experience with Winston, other than I'm aware of it and its purpose. After a quick review of the source on github, I'd say that no, winston is not truly async in all aspects.
emit
, but EventEmitter
is not async.callback
), but are not always async.The Console
transport calls callback
without a nextTick - it has an async-style signature, but it is still within the same tick, i.e.:
Console.prototype.log = function (level, msg, meta, callback) {
if (this.silent) {
return callback(null, true);
}
//...
if (level === 'error' || level === 'debug') {
process.stderr.write(output + '\n');
} else {
process.stdout.write(output + '\n');
}
//
// Emit the `logged` event immediately because the event loop
// will not exit until `process.stdout` has drained anyway.
//
self.emit('logged');
callback(null, true);
};
Logger
is similar to Console
as mentioned in previous in that it issues callbacks immediately w/o a nextTick
(or some other real async op). It does use the async
module, but that is not asynchronous on all accounts either, i.e.:
function cb(err) {
if (callback) {
if (err) return callback(err);
callback(null, level, msg, meta);
}
callback = null;
if (!err) {
self.emit('logged', level, msg, meta);
}
}
async.forEach(this._names, emit, cb);
I will give Winston that its File
transport is actually async, but only because fs
is.
Don't forget that console.log
is async within Node anyways... at least in my experience (when doing time-precision logging down to ms and even hrtime, results are sometimes out of order).