move intercept logs to utils

This commit is contained in:
Iuri Matias 2018-07-27 17:20:36 -04:00 committed by Pascal Precht
parent 1e7f0ada5b
commit ac4b74588e
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 25 additions and 0 deletions

View File

@ -494,6 +494,31 @@ function timer(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
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,