forked from megahertz/electron-log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
50 lines (39 loc) · 1.02 KB
/
renderer.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';
module.exports = null;
var ipcRenderer;
try {
ipcRenderer = require('electron').ipcRenderer;
} catch (e) {
ipcRenderer = null;
}
var originalConsole = require('./lib/original-console');
if (ipcRenderer) {
module.exports = {
error: log.bind(null, 'error'),
warn: log.bind(null, 'warn'),
info: log.bind(null, 'info'),
verbose: log.bind(null, 'verbose'),
debug: log.bind(null, 'debug'),
silly: log.bind(null, 'silly'),
log: log.bind(null, 'info')
};
module.exports.default = module.exports;
ipcRenderer.on('__ELECTRON_LOG_RENDERER__', function(event, level, text) {
if (level === 'verbose') {
level = 'log';
} else if (level === 'silly') {
level = 'debug';
}
originalConsole[level](text);
});
}
function log() {
var data = Array.prototype.slice.call(arguments);
data = data.map(function(obj) {
if (obj instanceof Error) {
obj = obj.stack || obj;
}
return obj;
});
ipcRenderer.send('__ELECTRON_LOG__', data);
}