Skip to content

Commit

Permalink
Line simplification for development (#366)
Browse files Browse the repository at this point in the history
* Use local time by default when prettifying logs

Signed-off-by: Matteo Collina <[email protected]>

* Ignore hostname by default

Signed-off-by: Matteo Collina <[email protected]>

* Update docs

Signed-off-by: Matteo Collina <[email protected]>

* Update test/basic.test.js

Co-authored-by: James Sumners <[email protected]>

* fixup

Signed-off-by: Matteo Collina <[email protected]>

Co-authored-by: James Sumners <[email protected]>
  • Loading branch information
mcollina and jsumners authored Aug 10, 2022
1 parent 405415c commit 429d5f1
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 104 deletions.
1 change: 0 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ts: false
jsx: false
flow: false
jobs: 1
files:
- 'test/**/*.test.js'
8 changes: 5 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Coverage Status](https://img.shields.io/coveralls/github/pinojs/pino-pretty)](https://coveralls.io/github/pinojs/pino-pretty?branch=master)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)

This module provides a basic [ndjson](http://ndjson.org/) formatter. If an
This module provides a basic [ndjson](http://ndjson.org/) formatter to be used in __development__. If an
incoming line looks like it could be a log line from an ndjson logger, in
particular the [Pino](https://getpino.io/) logging library, then it will apply
extra formatting by considering things like the log level and timestamp.
Expand All @@ -20,7 +20,7 @@ A standard Pino log line like:
Will format to:

```
[1522431328992] INFO (42 on foo): hello world
[17:35:28.992] INFO (42): hello world
```

If you landed on this page due to the deprecation of the `prettyPrint` option
Expand Down Expand Up @@ -84,13 +84,15 @@ node app.js | pino-pretty
date and time string. This flag also can set the format string to apply when
translating the date to a human-readable format. For a list of available pattern
letters, see the [`dateformat` documentation](https://www.npmjs.com/package/dateformat).
- The default format is `yyyy-mm-dd HH:MM:ss.l o` in UTC.
- The default format is `HH:MM:ss.l` in the local timezone.
- Require a `UTC:` prefix to translate time to UTC, e.g. `UTC:yyyy-mm-dd HH:MM:ss.l o`.
- Require a `SYS:` prefix to translate time to the local system's time zone. A
shortcut `SYS:standard` to translate time to `yyyy-mm-dd HH:MM:ss.l o` in
system time zone.
- `--ignore` (`-i`): Ignore one or several keys, nested keys are supported with each property delimited by a dot character (`.`),
keys may be escaped to target property names that contains the delimiter itself:
(`-i time,hostname,req.headers,log\\.domain\\.corp/foo`)
Default: `hostname`.
- `--hideObject` (`-H`): Hide objects from output (but not error object)
- `--singleLine` (`-S`): Print each log message on a single line (errors will still be multi-line)
- `--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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ const defaultOptions = {
messageKey: MESSAGE_KEY,
messageFormat: false,
timestampKey: TIMESTAMP_KEY,
translateTime: false,
translateTime: true,
useMetadata: false,
outputStream: process.stdout,
customPrettifiers: {},
hideObject: false,
ignore: 'hostname',
singleLine: false
}

Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module.exports = {
DATE_FORMAT: 'yyyy-mm-dd HH:MM:ss.l o',
DATE_FORMAT_SIMPLE: 'HH:MM:ss.l',

ERROR_LIKE_KEYS: ['err', 'error'],

Expand Down
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
LEVEL_LABEL,
TIMESTAMP_KEY,
LOGGER_KEYS,
LEVELS
LEVELS,
DATE_FORMAT_SIMPLE
} = require('./constants')

module.exports = {
Expand Down Expand Up @@ -74,7 +75,7 @@ function formatTime (epoch, translateTime = false) {
}

if (translateTime === true) {
return dateformat(instant, 'UTC:' + DATE_FORMAT)
return dateformat(instant, DATE_FORMAT_SIMPLE)
}

const upperFormat = translateTime.toUpperCase()
Expand Down
Loading

0 comments on commit 429d5f1

Please sign in to comment.