Skip to content

Commit 7ebaa7a

Browse files
authored
Merge pull request #385 from embark-framework/console_logs_fix
intercept logs in the app itself - stopgap fix
2 parents 17c33ad + 1cfe46d commit 7ebaa7a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/core/engine.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,53 @@ class Engine {
3535
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
3636
return cb({name: 'Embark ' + self.version, status: 'on'});
3737
}, 0);
38+
39+
if (this.interceptLogs || this.interceptLogs === undefined) {
40+
this.doInterceptLogs();
41+
}
42+
}
43+
44+
doInterceptLogs() {
45+
var self = this;
46+
let context = {};
47+
context.console = console;
48+
49+
let normalizeInput = function(input) {
50+
let args = Object.values(input);
51+
if (args.length === 0) {
52+
return "";
53+
}
54+
if (args.length === 1) {
55+
if (Array.isArray(args[0])) { return args[0].join(','); }
56+
return args[0] || "";
57+
}
58+
return ('[' + args.map((x) => {
59+
if (x === null) { return "null"; }
60+
if (x === undefined) { return "undefined"; }
61+
if (Array.isArray(x)) { return x.join(','); }
62+
return x;
63+
}).toString() + ']');
64+
};
65+
66+
context.console.log = function() {
67+
self.logger.info(normalizeInput(arguments));
68+
};
69+
context.console.warn = function() {
70+
self.logger.warn(normalizeInput(arguments));
71+
};
72+
context.console.info = function() {
73+
self.logger.info(normalizeInput(arguments));
74+
};
75+
context.console.debug = function() {
76+
// TODO: ue JSON.stringify
77+
self.logger.debug(normalizeInput(arguments));
78+
};
79+
context.console.trace = function() {
80+
self.logger.trace(normalizeInput(arguments));
81+
};
82+
context.console.dir = function() {
83+
self.logger.dir(normalizeInput(arguments));
84+
};
3885
}
3986

4087
startMonitor() {

0 commit comments

Comments
 (0)