Override console.log in main process, handle non-strings (#1536)
This should allow us to get an insight into auto-update behavior and other low-level behaviors happening in the Electron process which would be useful for debugging. FREEBIE
This commit is contained in:
parent
0b7543b0f6
commit
fb674529f4
2 changed files with 48 additions and 2 deletions
|
@ -83,6 +83,39 @@ function fetch(logPath) {
|
|||
}
|
||||
|
||||
|
||||
function logAtLevel() {
|
||||
const level = arguments[0];
|
||||
const args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
if (logger) {
|
||||
// To avoid [Object object] in our log since console.log handles non-strings smoothly
|
||||
const str = args.map(function(item) {
|
||||
if (typeof item !== 'string') {
|
||||
try {
|
||||
return JSON.stringify(item);
|
||||
}
|
||||
catch (e) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
logger[level](str.join(' '));
|
||||
} else {
|
||||
console._log.apply(console, consoleArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console._log = console.log;
|
||||
console.log = _.partial(logAtLevel, 'info');
|
||||
console._error = console.error;
|
||||
console.error = _.partial(logAtLevel, 'error');
|
||||
console._warn = console.warn;
|
||||
console.warn = _.partial(logAtLevel, 'warn');
|
||||
|
||||
|
||||
module.exports = {
|
||||
initialize,
|
||||
getLogger,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue