-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
54 lines (40 loc) · 1.37 KB
/
logger.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
51
52
53
const http = require('http');
const https = require('https');
const { getConfigValue } = require('homegames-common');
const ERROR_REPORTING_ENABLED = getConfigValue('ERROR_REPORTING_ENABLED', false);
const API_URL = getConfigValue('API_URL', null);
const electronLog = require('electron-log');
const log = {
info: (msg) => {
electronLog.info(JSON.stringify({message: msg}));
},
warn: (msg) => {
electronLog.warn(JSON.stringify({message: msg}));
},
debug: (msg) => {
electronLog.debug(JSON.stringify({message: msg}));
},
error: (msg) => {
electronLog.error(msg);
if (ERROR_REPORTING_ENABLED && API_URL) {
const module = API_URL.startsWith('https') ? https : http;
const payload = JSON.stringify({ message: msg });
const hostname = new URL(API_URL).host;
const headers = {};
Object.assign(headers, {
'Content-Type': 'application/json',
'Content-Length': payload.length
});
const options = {
hostname,
path: '/bugs',
port: API_URL.startsWith('https') ? 443 : 80,
method: 'POST',
headers
};
let responseData = '';
module.request(options);
}
}
};
module.exports = log;