1 | #!/usr/bin/env node
|
2 |
|
3 | const fs = require('fs')
|
4 | const args = require('args')
|
5 | const pump = require('pump')
|
6 | const split = require('split2')
|
7 | const { Transform } = require('readable-stream')
|
8 | const prettyFactory = require('./')
|
9 | const CONSTANTS = require('./lib/constants')
|
10 |
|
11 | args
|
12 | .option(['c', 'colorize'], 'Force adding color sequences to the output')
|
13 | .option(['f', 'crlf'], 'Append CRLF instead of LF to formatted lines')
|
14 | .option(['e', 'errorProps'], 'Comma separated list of properties on error objects to show (`*` for all properties)', '')
|
15 | .option(['l', 'levelFirst'], 'Display the log level as the first output field')
|
16 | .option(['k', 'errorLikeObjectKeys'], 'Define which keys contain error objects (`-k err,error`)', 'err,error')
|
17 | .option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY)
|
18 | .option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY)
|
19 | .option(['t', 'translateTime'], 'Display epoch timestamps as UTC ISO format or according to an optional format string (default ISO 8601)')
|
20 | .option(['s', 'search'], 'Specify a search pattern according to jmespath')
|
21 | .option(['i', 'ignore'], 'Ignore one or several keys: (`-i time,hostname`)')
|
22 |
|
23 | args
|
24 | .example('cat log | pino-pretty', 'To prettify logs, simply pipe a log file through')
|
25 | .example('cat log | pino-pretty -m fooMessage', 'To highlight a string at a key other than \'msg\', use')
|
26 | .example('cat log | pino-pretty -a fooTimestamp', 'To display timestamp from a key other than \'time\', use')
|
27 | .example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option')
|
28 | .example('cat log | pino-pretty -t "SYS:yyyy-mm-dd HH:MM:ss"', 'To convert Epoch timestamps to local timezone format use the -t option with "SYS:" prefixed format string')
|
29 | .example('cat log | pino-pretty -l', 'To flip level and time/date in standard output use the -l option')
|
30 | .example('cat log | pino-pretty -s "msg == \'hello world\'"', 'Only prints messages with msg equals to \'hello world\'')
|
31 | .example('cat log | pino-pretty -i pid,hostname', 'Prettify logs but don\'t print pid and hostname')
|
32 |
|
33 | const opts = args.parse(process.argv)
|
34 | const pretty = prettyFactory(opts)
|
35 | const prettyTransport = new Transform({
|
36 | objectMode: true,
|
37 | transform (chunk, enc, cb) {
|
38 | const line = pretty(chunk.toString())
|
39 | if (line === undefined) return cb()
|
40 | cb(null, line)
|
41 | }
|
42 | })
|
43 |
|
44 | pump(process.stdin, split(), prettyTransport, process.stdout)
|
45 |
|
46 |
|
47 | if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) {
|
48 | process.once('SIGINT', function noOp () {})
|
49 | }
|