forked from megahertz/electron-log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (42 loc) · 1.31 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
var electron;
try {
electron = require('electron');
} catch (e) {
electron = null;
}
var log = require('./lib/log');
var transportConsole = require('./lib/transports/console');
var transportFile = require('./lib/transports/file');
var transportLogS = require('./lib/transports/log-s');
var transportRendererConsole = require('./lib/transports/renderer-console');
var transports = {
console: transportConsole,
file: transportFile,
logS: transportLogS,
rendererConsole: transportRendererConsole
};
module.exports = {
transports: transports,
error: log.bind(null, transports, 'error'),
warn: log.bind(null, transports, 'warn'),
info: log.bind(null, transports, 'info'),
verbose: log.bind(null, transports, 'verbose'),
debug: log.bind(null, transports, 'debug'),
silly: log.bind(null, transports, 'silly'),
log: log.bind(null, transports, 'info')
};
module.exports.default = module.exports;
if (electron && electron.ipcMain) {
electron.ipcMain.on('__ELECTRON_LOG__', onRendererLog);
var appName = electron.app.getName();
if (appName !== 'Electron') {
transportFile.appName = appName;
}
}
function onRendererLog(event, data) {
if (Array.isArray(data)) {
data.unshift(transports);
log.apply(null, data);
}
}