UNPKG

2.67 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const fs = require('fs')
4const args = require('args')
5const pump = require('pump')
6const split = require('split2')
7const { Transform } = require('readable-stream')
8const prettyFactory = require('./')
9const CONSTANTS = require('./lib/constants')
10
11args
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
23args
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
33const opts = args.parse(process.argv)
34const pretty = prettyFactory(opts)
35const 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
44pump(process.stdin, split(), prettyTransport, process.stdout)
45
46// https://github.com/pinojs/pino/pull/358
47if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) {
48 process.once('SIGINT', function noOp () {})
49}