-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
cli.js
60 lines (50 loc) · 1.19 KB
/
cli.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
#! /usr/bin/env node
'use strict'
const fs = require('fs')
const path = require('path')
const minimist = require('minimist')
const pumpify = require('pumpify')
const pinoPapertrail = require('./lib/pino-papertrail')
const pkg = require('./package.json')
const options = {
alias: {
version: 'v',
help: 'h',
echo: 'e',
host: 'H',
port: 'p',
connection: 'c',
appname: 'a',
'message-only': 'm'
},
default: {
appname: 'pino',
echo: true,
host: 'localhost',
port: '1234',
connection: 'udp',
'message-only': false
}
}
const argv = minimist(process.argv.slice(2), options)
if (argv.help) {
console.log(fs.readFileSync(path.join(__dirname, './usage.txt'), 'utf8'))
process.exit(0)
}
if (argv.version) {
console.log(`${pkg.name} v${pkg.version}`)
process.exit(0)
}
const parseJson = pinoPapertrail.parseJson()
const toSyslog = pinoPapertrail.toSyslog(argv)
const papertrail = pinoPapertrail.toPapertrail(argv)
function shutdown () {
try {
papertrail.close()
} catch (e) {
process.exit()
}
}
process.on('SIGTERM', function () { shutdown() })
const pipeline = pumpify(parseJson, toSyslog, papertrail)
process.stdin.pipe(pipeline)