Prettifier for Pino log lines
npm install @voiceflow/pino-pretty


This module provides a basic ndjson formatter. If an
incoming line looks like it could be a log line from an ndjson logger, in
particular the Pino logging library, then it will apply
extra formatting by considering things like the log level and timestamp.
A standard Pino log line like:
```
{"level":30,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo","v":1}
Will format to:
``
[1522431328992] INFO (42 on foo): hello world
Using the [example script][exscript] from the Pino module, and specifying
that logs should be colored and the time translated, we can see what the
prettified logs will look like:
!demo
[exscript]: https://github.com/pinojs/pino/blob/fc4c83b/example.js
`sh`
$ npm install -g pino-pretty
It's recommended to use pino-pretty with pino
by piping output to the CLI tool:
`sh`
node app.js | pino-pretty
- --colorize (-c): Adds terminal color escape sequences to the output.--crlf
- (-f): Appends carriage return and line feed, instead of just a line--errorProps
feed, to the formatted log line.
- (-e): When formatting an error object, display this list''
of properties. The list should be a comma separated list of properties Default: .--levelFirst
- (-l): Display the log level name before the logged date and time.--errorLikeObjectKeys
- (-k): Define the log keys that are associated witherr,error
error like objects. Default: .--messageKey
- (-m): Define the key that contains the main log message.msg
Default: .--levelKey
- (--levelKey): Define the key that contains the level of the log.level
Default: .--levelLabel
- (-b): Output the log level using the specified label.levelLabel
Default: .--messageFormat
- (-o): Format output of message, e.g. {levelLabel} - {pid} - url:{request.url} will output message: INFO - 1123 - url:localhost:3000/testfalse
Default: --timestampKey
- (-a): Define the key that contains the log timestamp.time
Default: .--translateTime
- (-t): Translate the epoch time value into a human readabledateformat
date and time string. This flag also can set the format string to apply when
translating the date to human readable format. For a list of available pattern
letters see the documentation.yyyy-mm-dd HH:MM:ss.l o
- The default format is in UTC.SYS:
- Require a prefix to translate time to the local system's timezone. ASYS:standard
shortcut to translate time to yyyy-mm-dd HH:MM:ss.l o in--search
system timezone.
- (-s): Specify a search pattern according to--ignore
jmespath.
- (-i): Ignore one or several keys: (-i time,hostname)--hideObject
- (-H): Hide objects from output (but not error object)--config
- : Specify a path to a config file containing the pino-pretty options. pino-pretty will attempt to read from a .pino-prettyrc in your current directory (process.cwd) if not specified
We recommend against using pino-pretty in production, and highlypino-pretty
recommend installing as a development dependency.
When installed, pino-pretty will be used by pino as the default
prettifier.
Install pino-pretty alongside pino and set theprettyPrint option to true:
`js
const pino = require('pino')
const logger = pino({
prettyPrint: true
})
logger.info('hi')
`
The prettyPrint option can also be an object containing pretty-print
options:
`js
const pino = require('pino')
const logger = pino({
prettyPrint: { colorize: true }
})
logger.info('hi')
`
See the Options section for all possible options.
pino-pretty exports a factory function that can be used to format log strings.
This factory function is used internally by Pino, and accepts an options argument
with keys corresponding to the options described in CLI Arguments:
`jsbar
{
colorize: chalk.supportsColor, // --colorize
crlf: false, // --crlf
errorLikeObjectKeys: ['err', 'error'], // --errorLikeObjectKeys
errorProps: '', // --errorProps
levelFirst: false, // --levelFirst
messageKey: 'msg', // --messageKey
levelKey: 'level', // --levelKey
messageFormat: false // --messageFormat
timestampKey: 'time', // --timestampKey
translateTime: false, // --translateTime
search: 'foo == ', // --search`
ignore: 'pid,hostname', // --ignore,
hideObject: false // --hideObject
customPrettifiers: {}
}
The colorize default followschalk.supportsColor.
customPrettifiers option provides the ability to add a custom prettify functioncustomPrettifiers
for specific log properties. is an object, where keys arequery
log properties which will be prettified and value is the prettify function itself.
For example, if a log line contains a property,`
you can specify a prettifier for it:js``
{
customPrettifiers: {
query: prettifyQuery
}
}
//...
const prettifyQuery = value => {
// do some prettify magic
}
MIT License