You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/test/defer-logger.js

38 lines
652 B
JavaScript

'use strict';
var winston = require('winston');
var Transport = require('winston-transport');
var winstonLogged = [];
class DeferLogger extends Transport {
constructor(opts) {
super(opts);
this.logged = opts.logged;
}
log(info, callback) {
setImmediate(() => {
this.emit('logged', info);
});
this.logged.push([info.level, info.message]);
callback();
}
}
before(function () {
// defer winston logs until the end
winston.clear();
winston.add(new DeferLogger({ logged: winstonLogged }));
});
after(function () {
console.log('\n\n');
winstonLogged.forEach(function (args) {
console.log(args[0] + ' ' + args[1]);
});
});