-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpsyslog.js
63 lines (54 loc) · 1.3 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
'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 { buildOptions } = require('./lib/utils')
const longOpts = {
modern: Boolean,
appname: String,
cee: Boolean,
facility: Number,
includeProperties: String,
messageOnly: Boolean,
tz: String,
newline: Boolean,
structuredData: String,
config: String,
sync: Boolean
}
const shortOpts = {
m: '--modern',
a: '--appname',
f: '--facility',
p: '--includeProperties',
mo: '--messageOnly',
n: '--newline',
s: '--structuredData',
c: '--config',
sy: '--sync'
}
const args = nopt(longOpts, shortOpts)
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}`)
}
}
const options = buildOptions(jsonOptions, args)
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) })