diff --git a/lib/core/engine.js b/lib/core/engine.js index da632e3f..36cc4102 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -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() {