move intercept logs to utils

This commit is contained in:
Iuri Matias 2018-07-27 17:20:36 -04:00
parent 4919114f36
commit 46f5760c18
2 changed files with 28 additions and 28 deletions

View File

@ -33,36 +33,10 @@ class Engine {
this.isDev = this.config && this.config.blockchainConfig && (this.config.blockchainConfig.isDev || this.config.blockchainConfig.default);
if (this.interceptLogs || this.interceptLogs === undefined) {
this.doInterceptLogs();
utils.interceptLogs(console, this.logger);
}
}
doInterceptLogs() {
var self = this;
let context = {};
context.console = console;
context.console.log = function() {
self.logger.info(utils.normalizeInput(arguments));
};
context.console.warn = function() {
self.logger.warn(utils.normalizeInput(arguments));
};
context.console.info = function() {
self.logger.info(utils.normalizeInput(arguments));
};
context.console.debug = function() {
// TODO: ue JSON.stringify
self.logger.debug(utils.normalizeInput(arguments));
};
context.console.trace = function() {
self.logger.trace(utils.normalizeInput(arguments));
};
context.console.dir = function() {
self.logger.dir(utils.normalizeInput(arguments));
};
}
registerModule(moduleName, options) {
this.plugins.loadInternalPlugin(moduleName, options || {});
}

View File

@ -383,6 +383,31 @@ function last(array) {
return array[array.length - 1];
}
function interceptLogs(consoleContext, logger) {
let context = {};
context.console = consoleContext;
context.console.log = function() {
logger.info(normalizeInput(arguments));
};
context.console.warn = function() {
logger.warn(normalizeInput(arguments));
};
context.console.info = function() {
logger.info(normalizeInput(arguments));
};
context.console.debug = function() {
// TODO: ue JSON.stringify
logger.debug(normalizeInput(arguments));
};
context.console.trace = function() {
logger.trace(normalizeInput(arguments));
};
context.console.dir = function() {
logger.dir(normalizeInput(arguments));
};
}
module.exports = {
joinPath,
dirname,
@ -419,5 +444,6 @@ module.exports = {
compact,
groupBy,
sample,
last
last,
interceptLogs
};