Files
NodeBB/test/defer-logger.js

38 lines
640 B
JavaScript
Raw Normal View History

'use strict';
2021-02-04 00:06:15 -07:00
const winston = require('winston');
const Transport = require('winston-transport');
2021-02-04 00:06:15 -07:00
const 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();
}
}
2021-02-04 00:01:39 -07:00
before(() => {
// defer winston logs until the end
winston.clear();
winston.add(new DeferLogger({ logged: winstonLogged }));
});
2021-02-04 00:01:39 -07:00
after(() => {
console.log('\n\n');
2021-02-04 00:01:39 -07:00
winstonLogged.forEach((args) => {
2021-02-03 23:59:08 -07:00
console.log(`${args[0]} ${args[1]}`);
});
});