diff --git a/lib/core/engine.js b/lib/core/engine.js index f1b9b26e4..09148cf4e 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -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 || {}); } diff --git a/lib/utils/utils.js b/lib/utils/utils.js index b84cbdf64..e65601450 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -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 };