forked from sethblack/pm2-gelf-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (49 loc) · 1.49 KB
/
app.js
File metadata and controls
60 lines (49 loc) · 1.49 KB
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
54
55
56
57
58
59
60
const pm2 = require('pm2');
const pmx = require('pmx'); // docs say pmx is deprecated, module:generate still uses it, I confuze
const gelflog = require('gelf-pro');
const os = require('os');
const conf = pmx.initModule({
widget: {
logo: 'https://app.keymetrics.io/img/logo/keymetrics-300.png',
theme: ['#141A1F', '#222222', '#3ff', '#3ff'],
},
});
const errEnabled = (typeof conf.errEnabled === 'undefined') ? true:conf.errEnabled;
const outEnabled = (typeof conf.outEnabled === 'undefined') ? true:conf.outEnabled;
gelflog.setConfig({
adapterName: conf.gelfAdapterName,
adapterOptions: {
host: conf.graylogHost,
port: conf.graylogPort,
},
});
if (conf.graylogFields) {
try {
const fields = JSON.parse(conf.graylogFields);
gelflog.setConfig({ fields });
} catch (ex) {
console.log(`Could not parse JSON ${ex}`); // eslint-disable-line no-console
}
}
pm2.Client.launchBus((err, bus) => {
if (err) return;
bus.on('log:out', (log) => {
if (log.process.name === 'pm2-gelf-pro') return;
console.log(outEnabled);
if (!outEnabled) return;
const extra = {machine: os.hostname(), app: log.process.name};
gelflog.info(log.data, extra);
});
bus.on('log:err', (log) => {
if (log.process.name === 'pm2-gelf-pro') return;
if (!errEnabled) return;
const extra = {machine: os.hostname, app: log.process.name};
gelflog.error(log.data, extra);
});
bus.on('close', () => {
pm2.disconnectBus();
});
});
module.exports = {
gelflog,
};