* upgrade to winston 3.1 * fix winston in web/install and testsv1.18.x
parent
6fb11d37ff
commit
85c60316ed
@ -1,40 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var winston = require('winston');
|
||||
var Transport = require('winston-transport');
|
||||
|
||||
function DeferLogger(options) {
|
||||
options = options || {};
|
||||
|
||||
this.name = 'DeferLogger';
|
||||
this.level = options.level || 'info';
|
||||
|
||||
this.logged = options.logged;
|
||||
}
|
||||
var winstonLogged = [];
|
||||
|
||||
util.inherits(DeferLogger, winston.Transport);
|
||||
class DeferLogger extends Transport {
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this.logged = opts.logged;
|
||||
}
|
||||
|
||||
DeferLogger.prototype.log = function log(level, msg, meta, callback) {
|
||||
this.logged.push([level, msg, meta]);
|
||||
callback(null, true);
|
||||
};
|
||||
log(info, callback) {
|
||||
setImmediate(() => {
|
||||
this.emit('logged', info);
|
||||
});
|
||||
|
||||
var winstonLogged = [];
|
||||
this.logged.push([info.level, info.message]);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
before(function () {
|
||||
// defer winston logs until the end
|
||||
winston.remove(winston.transports.Console);
|
||||
winston.clear();
|
||||
|
||||
winston.add(DeferLogger, {
|
||||
logged: winstonLogged,
|
||||
});
|
||||
winston.add(new DeferLogger({ logged: winstonLogged }));
|
||||
});
|
||||
|
||||
after(function () {
|
||||
console.log('\n\n');
|
||||
|
||||
var con = new winston.transports.Console();
|
||||
winstonLogged.forEach(function (args) {
|
||||
con.log(args[0], args[1], args[2], function () {});
|
||||
console.log(args[0] + ' ' + args[1]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue