UNPKG

4.44 kBMarkdownView Raw
1<a id="intro"></a>
2# pino-pretty
3
4[![Build Status](https://travis-ci.org/pinojs/pino-pretty.svg?branch=master)](https://travis-ci.org/pinojs/pino-pretty)
5[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino-pretty/badge.svg?branch=master)](https://coveralls.io/github/pinojs/pino-pretty?branch=master)
6
7This module provides a basic [ndjson](http://ndjson.org/) formatter. If an
8incoming line looks like it could be a log line from an ndjson logger, in
9particular the [Pino](https://getpino.io/) logging library, then it will apply
10extra formatting by considering things like the log level and timestamp.
11
12A standard Pino log line like:
13
14```
15{"level":30,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo","v":1}
16```
17
18Will format to:
19
20```
21[1522431328992] INFO (42 on foo): hello world
22```
23
24<a id="example"></a>
25## Example
26
27Using the [example script][exscript] from the Pino module, and specifying
28that logs should be colored and the time translated, we can see what the
29prettified logs will look like:
30
31![demo](demo.png)
32
33[exscript]: https://github.com/pinojs/pino/blob/fc4c83b/example.js
34
35<a id="install"></a>
36## Install
37
38```sh
39$ npm install -g pino-pretty
40```
41
42<a id="usage"></a>
43## Usage
44
45It's recommended to use `pino-pretty` with `pino`
46by piping output to the CLI tool:
47
48```sh
49pino app.js | pino-pretty
50```
51
52<a id="cliargs"></a>
53### CLI Arguments
54
55- `--colorize` (`-c`): Adds terminal color escape sequences to the output.
56- `--crlf` (`-f`): Appends carriage return and line feed, instead of just a line
57 feed, to the formatted log line.
58- `--errorProps` (`-e`): When formatting an error object, display this list
59 of properties. The list should be a comma separated list of properties Default: `''`.
60- `--levelFirst` (`-l`): Display the log level name before the logged date and time.
61- `--errorLikeObjectKeys` (`-k`): Define the log keys that are associated with
62 error like objects. Default: `err,error`.
63- `--messageKey` (`-m`): Define the key that contains the main log message.
64 Default: `msg`.
65- `--timestampKey` (`-m`): Define the key that contains the log timestamp.
66 Default: `time`.
67- `--translateTime` (`-t`): Translate the epoch time value into a human readable
68 date and time string. This flag also can set the format string to apply when
69 translating the date to human readable format. For a list of available pattern
70 letters see the [`dateformat` documentation](https://www.npmjs.com/package/dateformat).
71 - The default format is `yyyy-mm-dd HH:MM:ss.l o` in UTC.
72 - Require a `SYS:` prefix to translate time to the local system's timezone. A
73 shortcut `SYS:standard` to translate time to `yyyy-mm-dd HH:MM:ss.l o` in
74 system timezone.
75- `--search` (`-s`): Specify a search pattern according to
76 [jmespath](http://jmespath.org/).
77- `--ignore` (`-i`): Ignore one or several keys: (`-i time,hostname`)
78
79<a id="integration"></a>
80## Programmatic Integration
81
82We recommend against using `pino-pretty` in production, and highly
83recommend installing `pino-pretty` as a development dependency.
84
85When installed, `pino-pretty` will be used by `pino` as the default
86prettifier.
87
88Install `pino-pretty` alongside `pino` and set the
89`prettyPrint` option to `true`:
90
91```js
92const pino = require('pino')
93const logger = pino({
94 prettyPrint: true
95})
96
97logger.info('hi')
98```
99
100The `prettyPrint` option can also be an object containing `pretty-print`
101options:
102
103```js
104const pino = require('pino')
105const logger = pino({
106 prettyPrint: { colorize: true }
107})
108
109logger.info('hi')
110```
111
112See the [Options](#options) section for all possible options.
113
114<a id="options"></a>
115### Options
116
117`pino-pretty` exports a factory function that can be used to format log strings.
118This factory function is used internally by Pino, and accepts an options argument
119with keys corresponding to the options described in [CLI Arguments](#cliargs):
120
121```js
122{
123 colorize: chalk.supportsColor, // --colorize
124 crlf: false, // --crlf
125 errorLikeObjectKeys: ['err', 'error'], // --errorLikeObjectKeys
126 errorProps: '', // --errorProps
127 levelFirst: false, // --levelFirst
128 messageKey: 'msg', // --messageKey
129 timestampKey: 'time', // --timestampKey
130 translateTime: false, // --translateTime
131 search: 'foo == `bar`', // --search
132 ignore: 'pid,hostname' // --ignore
133}
134```
135
136The `colorize` default follows
137[`chalk.supportsColor](https://www.npmjs.com/package/chalk#chalksupportscolor).
138
139<a id="license"><a>
140## License
141
142MIT License