add log.js module for renderer logging

This commit is contained in:
Feross Aboukhadijeh
2016-03-21 01:57:12 -07:00
parent d3692928b6
commit 48c356dac3
6 changed files with 48 additions and 12 deletions

31
main/log.js Normal file
View File

@@ -0,0 +1,31 @@
module.exports = log
module.exports.error = error
/**
* In the main electron process, we do not use console.log() statements because they do
* not show up in a convenient location when running the packaged (i.e. production)
* version of the app. Instead use this module, which sends the logs to the main window
* where they can be viewed in Developer Tools.
*/
var electron = require('electron')
var windows = require('./windows')
var app = electron.app
function log (...args) {
if (app.ipcReady) {
windows.main.send('log', ...args)
} else {
app.on('ipcReady', () => windows.main.send('log', ...args))
}
}
function error (...args) {
if (app.ipcReady) {
windows.main.send('error', ...args)
} else {
app.on('ipcReady', () => windows.main.send('error', ...args))
}
}