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