upgrade to winston 3.1, closes #6590 (#6838)

* upgrade to winston 3.1

* fix winston in web/install and tests
This commit is contained in:
Barış Soner Uşaklı
2018-10-16 13:07:13 -04:00
committed by GitHub
parent 6fb11d37ff
commit 85c60316ed
10 changed files with 93 additions and 54 deletions

View File

@@ -1,40 +1,37 @@
'use strict';
var util = require('util');
var winston = require('winston');
function DeferLogger(options) {
options = options || {};
this.name = 'DeferLogger';
this.level = options.level || 'info';
this.logged = options.logged;
}
util.inherits(DeferLogger, winston.Transport);
DeferLogger.prototype.log = function log(level, msg, meta, callback) {
this.logged.push([level, msg, meta]);
callback(null, true);
};
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.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]);
});
});