Is Winston's logging system really Async
I have no experience with Winston other than what I know about it and his goals. After a quick overview of the source on github, I would say no, winston is not truly asynchronous in all aspects.
- It does
emit
, but isEventEmitter
not async. - Methods are type signed asynchronously (w /
callback
), but not always async.
Console
transport calls callback
without nextTick - it has type signatures of an asynchronous type, but it is still in 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 toConsole
as mentioned in the previous one in that it immediately calls w / oa callbacks nextTick
(or some other real async op). It uses a module async
, but that is not asynchronous across all accounts, either , that is:
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'll give Winston that his transport is File
actually asynchronous, but only because it fs
is .
Remember that "console functions are synchronous when the endpoint is a terminal or file."
source to share