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 functions are synchronous when the destination is a terminal or a file" anyways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With