forked from pinojs/pino-syslog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psyslog.js
71 lines (62 loc) 路 1.44 KB
/
psyslog.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict'
const nopt = require('nopt')
const path = require('path')
const pump = require('pump')
const split2 = require('split2')
const parseJson = require('fast-json-parse')
const defaults = {
modern: true,
appname: 'none',
cee: false,
facility: 16,
includeProperties: [],
messageOnly: false,
tz: 'Etc/UTC',
newline: false
}
const longOpts = {
modern: Boolean,
appname: String,
cee: Boolean,
facility: Number,
includeProperties: String,
messageOnly: Boolean,
tz: String,
newline: Boolean,
structuredData: String,
config: String
}
const shortOpts = {
m: '--modern',
a: '--appname',
f: '--facility',
p: '--includeProperties',
mo: '--messageOnly',
n: '--newline',
s: '--structuredData',
c: '--config'
}
const args = nopt(longOpts, shortOpts)
let options = Object.assign({}, defaults, args)
let jsonOptions = {}
if (args.config) {
try {
jsonOptions = require(path.resolve(args.config))
} catch (e) {
process.stderr.write(`could not load settings file, using defaults: ${e.message}`)
}
options = Object.assign({}, jsonOptions, options)
}
let myTransport
if (options.modern) {
myTransport = require('./lib/rfc5424.js')(options)
} else {
myTransport = require('./lib/rfc3164.js')(options)
}
function parser (str) {
const result = parseJson(str)
if (result.err) return
return result.value
}
pump(process.stdin, split2(parser), myTransport)
process.on('SIGINT', () => { process.exit(0) })