Sometimes it's helpful to save critical electron events to the log file.
log.eventLogger.startLogging(options?)
;
By default, it saves the following events:
certificate-error
,child-process-gone
,render-process-gone
ofapp
crashed
,gpu-process-crashed
ofwebContents
did-fail-load
,did-fail-provisional-load
,plugin-crashed
,preload-error
of every WebContents. You can switch any event on/off.
Start saving event logs.
Stop saving logs.
Set logging options.
Default: '{eventSource}#{eventName}:'
Custom format function example:
log.eventLogger.format = ({ args, event, eventName, eventSource }) => {
return [`${eventSource}#${eventName}:`, JSON.stringify(args)];
};
A set of functions which formats a specific event.
log.eventLogger.formatters.webContents['console-message'] = ({
args: [level, message, line, sourceId],
event,
eventName,
eventSource
}) => {
const webContents = event.sender;
if (level > 2) {
return undefined;
}
return { message, source: `${sourceId}:${line}`, url: webContents?.getURL() };
};
Allow switching specific events on/off easily
Default:
log.eventLogger.events = {
app: {
'certificate-error': true,
'child-process-gone': true,
'render-process-gone': true,
},
webContents: {
'did-fail-load': true,
'did-fail-provisional-load': true,
'plugin-crashed': true,
'preload-error': true,
'unresponsive': true,
}
}
Which log level is used for logging
Default: 'warn'
Which log scope is used for logging
Default: ''