intercept logs in the app itself - stopgap fix

This commit is contained in:
Iuri Matias 2018-04-26 17:01:11 -04:00
parent 17c33ad075
commit 1cfe46db55

View File

@ -35,6 +35,53 @@ class Engine {
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
return cb({name: 'Embark ' + self.version, status: 'on'});
}, 0);
if (this.interceptLogs || this.interceptLogs === undefined) {
this.doInterceptLogs();
}
}
doInterceptLogs() {
var self = this;
let context = {};
context.console = console;
let normalizeInput = function(input) {
let args = Object.values(input);
if (args.length === 0) {
return "";
}
if (args.length === 1) {
if (Array.isArray(args[0])) { return args[0].join(','); }
return args[0] || "";
}
return ('[' + args.map((x) => {
if (x === null) { return "null"; }
if (x === undefined) { return "undefined"; }
if (Array.isArray(x)) { return x.join(','); }
return x;
}).toString() + ']');
};
context.console.log = function() {
self.logger.info(normalizeInput(arguments));
};
context.console.warn = function() {
self.logger.warn(normalizeInput(arguments));
};
context.console.info = function() {
self.logger.info(normalizeInput(arguments));
};
context.console.debug = function() {
// TODO: ue JSON.stringify
self.logger.debug(normalizeInput(arguments));
};
context.console.trace = function() {
self.logger.trace(normalizeInput(arguments));
};
context.console.dir = function() {
self.logger.dir(normalizeInput(arguments));
};
}
startMonitor() {