Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pinojs/pino-pretty
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.0.1
Choose a base ref
...
head repository: pinojs/pino-pretty
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.0
Choose a head ref
  • 8 commits
  • 9 files changed
  • 6 contributors

Commits on Sep 21, 2021

  1. fix: dateformat migrated to esm (#234)

    * fix: esm package migration
    
    * ci: use continue-on-error for coveralls
    
    * chore: use dateformat ^4.6.3
    
    * ci: update coveralls handling
    climba03003 authored Sep 21, 2021
    Copy the full SHA
    7e802b4 View commit details
  2. Add support for minimumLevel (#233)

    * Add support for minimumLevel
    
    * Update Readme.md
    
    Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
    bitjson and mcollina authored Sep 21, 2021
    Copy the full SHA
    a1526b0 View commit details

Commits on Sep 22, 2021

  1. Copy the full SHA
    7a0c876 View commit details

Commits on Sep 28, 2021

  1. Bump actions/setup-node from 2.4.0 to 2.4.1 (#239)

    Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.0 to 2.4.1.
    - [Release notes](https://github.com/actions/setup-node/releases)
    - [Commits](actions/setup-node@v2.4.0...v2.4.1)
    
    ---
    updated-dependencies:
    - dependency-name: actions/setup-node
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Sep 28, 2021
    Copy the full SHA
    b701def View commit details

Commits on Oct 4, 2021

  1. Bump pino-abstract-transport from 0.3.0 to 0.4.0 (#240)

    Bumps [pino-abstract-transport](https://github.com/pinojs/pino-abstract-transport) from 0.3.0 to 0.4.0.
    - [Release notes](https://github.com/pinojs/pino-abstract-transport/releases)
    - [Commits](https://github.com/pinojs/pino-abstract-transport/commits/v0.4.0)
    
    ---
    updated-dependencies:
    - dependency-name: pino-abstract-transport
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 4, 2021
    Copy the full SHA
    b04408a View commit details

Commits on Oct 13, 2021

  1. Bump tsd from 0.17.0 to 0.18.0 (#243)

    Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.17.0 to 0.18.0.
    - [Release notes](https://github.com/SamVerschueren/tsd/releases)
    - [Commits](tsdjs/tsd@v0.17.0...v0.18.0)
    
    ---
    updated-dependencies:
    - dependency-name: tsd
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 13, 2021
    Copy the full SHA
    9af5d96 View commit details

Commits on Oct 14, 2021

  1. Updated to pino@7 (#245)

    * Updated to pino@7
    
    * restored old warning
    mcollina authored Oct 14, 2021
    Copy the full SHA
    35d3410 View commit details
  2. Bumped v7.1.0

    mcollina committed Oct 14, 2021
    Copy the full SHA
    bfea42e View commit details
Showing with 228 additions and 42 deletions.
  1. +15 −2 .github/workflows/ci.yml
  2. +2 −0 Readme.md
  3. +4 −2 bin.js
  4. +9 −1 index.js
  5. +5 −3 lib/utils.js
  6. +6 −6 package.json
  7. +48 −1 test/basic.test.js
  8. +1 −1 test/cli-rc.test.js
  9. +138 −26 test/error-objects.test.js
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -13,16 +13,18 @@ on:
jobs:
build:
runs-on: ${{ matrix.os }}
outputs:
COVERALLS: ${{ steps.coveralls-trigger.outputs.COVERALLS_TRIGGER }}
strategy:
matrix:
node-version: [10, 12, 14, 16]
node-version: [12, 14, 16]
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Use Node.js
uses: actions/setup-node@v2.4.0
uses: actions/setup-node@v2.4.1
with:
node-version: ${{ matrix.node-version }}

@@ -39,15 +41,26 @@ jobs:
run: npm run ci

- name: Coveralls Parallel
id: coveralls-parallel
uses: coverallsapp/github-action@1.1.3
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel: true
flag-name: run-${{ matrix.node-version }}-${{ matrix.os }}

- name: Should Trigger coverallsapp/github-action@master
id: coveralls-trigger
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
# when continue-on-error failed, outcome is failure and conclusion is success
if: steps.coveralls-parallel.conclusion == 'success' && steps.coveralls-parallel.outcome != 'success'
run: |
echo "::set-output name=COVERALLS_TRIGGER::failure"
coverage:
needs: build
runs-on: ubuntu-latest
if: needs.test.outputs.COVERALLS != 'failure'
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@1.1.3
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ node app.js | pino-pretty
feed, to the formatted log line.
- `--errorProps` (`-e`): When formatting an error object, display this list
of properties. The list should be a comma-separated list of properties Default: `''`.
Do not use this option if logging from pino@7. Support will be removed from future verions.
- `--levelFirst` (`-l`): Display the log level name before the logged date and time.
- `--errorLikeObjectKeys` (`-k`): Define the log keys that are associated with
error like objects. Default: `err,error`.
@@ -69,6 +70,7 @@ node app.js | pino-pretty
Default: `level`.
- `--levelLabel` (`-b`): Output the log level using the specified label.
Default: `levelLabel`.
- `--minimumLevel` (`-L`): Hide messages below the specified log level. Accepts a number, `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. If any more filtering is required, consider using [`jq`](https://stedolan.github.io/jq/).
- `--messageFormat` (`-o`): Format output of message, e.g. `{levelLabel} - {pid} - url:{request.url}` will output message: `INFO - 1123 - url:localhost:3000/test`
Default: `false`
- `--timestampKey` (`-a`): Define the key that contains the log timestamp.
6 changes: 4 additions & 2 deletions bin.js
Original file line number Diff line number Diff line change
@@ -35,14 +35,14 @@ args
.option(['f', 'crlf'], 'Append CRLF instead of LF to formatted lines')
.option(['e', 'errorProps'], 'Comma separated list of properties on error objects to show (`*` for all properties) (defaults to ``)')
.option(['l', 'levelFirst'], 'Display the log level as the first output field')
.option(['L', 'minimumLevel'], 'Hide messages below the specified log level')
.option(['k', 'errorLikeObjectKeys'], 'Define which keys contain error objects (`-k err,error`) (defaults to `err,error`)')
.option(['m', 'messageKey'], 'Highlight the message under the specified key', CONSTANTS.MESSAGE_KEY)
.option('levelKey', 'Detect the log level under the specified key', CONSTANTS.LEVEL_KEY)
.option(['b', 'levelLabel'], 'Output the log level using the specified label', CONSTANTS.LEVEL_LABEL)
.option(['o', 'messageFormat'], 'Format output of message')
.option(['a', 'timestampKey'], 'Display the timestamp from the specified key', CONSTANTS.TIMESTAMP_KEY)
.option(['t', 'translateTime'], 'Display epoch timestamps as UTC ISO format or according to an optional format string (default ISO 8601)')
.option(['s', 'search'], 'Specify a search pattern according to jmespath')
.option(['i', 'ignore'], 'Ignore one or several keys: (`-i time,hostname`)')
.option(['H', 'hideObject'], 'Hide objects from output (but not error object)')
.option(['S', 'singleLine'], 'Print all non-error objects on a single line')
@@ -57,7 +57,7 @@ args
.example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option')
.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')
.example('cat log | pino-pretty -l', 'To flip level and time/date in standard output use the -l option')
.example('cat log | pino-pretty -s "msg == \'hello world\'"', 'Only prints messages with msg equals to \'hello world\'')
.example('cat log | pino-pretty -L info', 'Only prints messages with a minimum log level of info')
.example('cat log | pino-pretty -i pid,hostname', 'Prettify logs but don\'t print pid and hostname')
.example('cat log | pino-pretty --config=/path/to/config.json', 'Loads options from a config file')

@@ -67,13 +67,15 @@ let opts = args.parse(process.argv, {
mri: {
default: {
messageKey: DEFAULT_VALUE,
minimumLevel: DEFAULT_VALUE,
levelKey: DEFAULT_VALUE,
timestampKey: DEFAULT_VALUE
},
// NOTE: The following key-value pairs values should be in sync with the
// short version values defined in each `args.option([value, key], ...)`
alias: {
messageKey: 'm',
minimumLevel: 'L',
timestampKey: 'a'
}
}
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const sonic = require('sonic-boom')
const sjs = require('secure-json-parse')

const colors = require('./lib/colors')
const { ERROR_LIKE_KEYS, MESSAGE_KEY, TIMESTAMP_KEY } = require('./lib/constants')
const { ERROR_LIKE_KEYS, MESSAGE_KEY, TIMESTAMP_KEY, LEVEL_KEY, LEVEL_NAMES } = require('./lib/constants')
const {
isObject,
prettifyErrorLog,
@@ -52,6 +52,7 @@ function prettyFactory (options) {
const messageKey = opts.messageKey
const levelKey = opts.levelKey
const levelLabel = opts.levelLabel
const minimumLevel = opts.minimumLevel
const messageFormat = opts.messageFormat
const timestampKey = opts.timestampKey
const errorLikeObjectKeys = opts.errorLikeObjectKeys
@@ -77,6 +78,12 @@ function prettyFactory (options) {
log = inputData
}

if (minimumLevel) {
const minimum = LEVEL_NAMES[minimumLevel] || Number(minimumLevel)
const level = log[levelKey === undefined ? LEVEL_KEY : levelKey]
if (level < minimum) return
}

const prettifiedMessage = prettifyMessage({ log, messageKey, colorizer, messageFormat, levelLabel })

if (ignoreKeys) {
@@ -130,6 +137,7 @@ function prettyFactory (options) {
line += EOL
}

// pino@7+ does not log this anymore
if (log.type === 'Error' && log.stack) {
const prettifiedErrorLog = prettifyErrorLog({
log,
8 changes: 5 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -198,11 +198,11 @@ function prettifyErrorLog ({
// The nested object may have "logger" type keys but since they are not
// at the root level of the object being processed, we want to print them.
// Thus, we invoke with `excludeLoggerKeys: false`.
const prettifiedObject = prettifyObject({ input: log[key], errorLikeKeys, excludeLoggerKeys: false, eol, ident })
result = `${result}${key}: {${eol}${prettifiedObject}}${eol}`
const prettifiedObject = prettifyObject({ input: log[key], errorLikeKeys, excludeLoggerKeys: false, eol, ident: ident + ident })
result = `${result}${ident}${key}: {${eol}${prettifiedObject}${ident}}${eol}`
continue
}
result = `${result}${key}: ${log[key]}${eol}`
result = `${result}${ident}${key}: ${log[key]}${eol}`
}
}

@@ -471,6 +471,8 @@ function prettifyError ({ keyName, lines, eol, ident }) {
const indentation = ' '.repeat(indentSize)
const stackMessage = matches[2]
result += matches[1] + eol + indentation + JSON.parse(stackMessage).replace(/\n/g, eol + indentation)
} else {
result += line
}
} else {
result += line
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pino-pretty",
"version": "7.0.1",
"version": "7.1.0",
"description": "Prettifier for Pino log lines",
"type": "commonjs",
"main": "index.js",
@@ -33,11 +33,11 @@
],
"dependencies": {
"args": "^5.0.1",
"colorette": "^2.0.0",
"dateformat": "^4.5.1",
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-safe-stringify": "^2.0.7",
"joycon": "^3.0.0",
"pino-abstract-transport": "^0.3.0",
"pino-abstract-transport": "^0.4.0",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
"rfdc": "^1.3.0",
@@ -47,13 +47,13 @@
},
"devDependencies": {
"@types/node": "^16.9.2",
"pino": "^6.13.2",
"pino": "^7.0.0",
"pre-commit": "^1.2.2",
"rimraf": "^3.0.2",
"snazzy": "^9.0.0",
"standard": "^16.0.3",
"tap": "^15.0.9",
"tsd": "^0.17.0",
"tsd": "^0.18.0",
"typescript": "^4.4.3"
},
"tsd": {
49 changes: 48 additions & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
@@ -443,6 +443,53 @@ test('basic prettifier tests', (t) => {
log.info('foo')
})

t.test('filter some lines based on minimumLevel', (t) => {
t.plan(3)
const pretty = prettyFactory({ minimumLevel: 'info' })
const expected = [
undefined,
undefined,
`[${epoch}] INFO (${pid} on ${hostname}): baz\n`
]
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.equal(
formatted,
expected.shift()
)
cb()
}
}))
log.info({ msg: 'foo', level: 10 })
log.info({ msg: 'bar', level: 20 })
// only this line will be formatted
log.info({ msg: 'baz', level: 30 })
})

t.test('filter lines based on minimumLevel using custom levels and level key', (t) => {
t.plan(3)
const pretty = prettyFactory({ minimumLevel: 20, levelKey: 'bar' })
const expected = [
undefined,
`[${epoch}] DEBUG (${pid} on ${hostname}): bar\n`,
`[${epoch}] INFO (${pid} on ${hostname}): baz\n`
]
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.equal(
formatted,
expected.shift()
)
cb()
}
}))
log.info({ msg: 'foo', bar: 10 })
log.info({ msg: 'bar', bar: 20 })
log.info({ msg: 'baz', bar: 30 })
})

t.test('formats a line with an undefined field', (t) => {
t.plan(1)
const pretty = prettyFactory()
@@ -494,7 +541,7 @@ test('basic prettifier tests', (t) => {
' "b": {',
' "c": "d"',
' },',
' "a": "[Circular]"',
' "a": "[Circular ~]"',
' }'
]
const pretty = prettyFactory()
2 changes: 1 addition & 1 deletion test/cli-rc.test.js
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ test('cli', (t) => {
// Validate that the time has been translated and correct message key has been used
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n')
t.equal(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\n querySql: SELECTT * FROM "test" WHERE id = $1;\n queryArgs: 12\n')
})
child.stdin.write('{"level":60,"time":1594416696006,"msg":"There was an error starting the process.","type":"Error","stack":"QueryError: Error during sql query: syntax error at or near SELECTT\\n at /home/me/projects/example/sql.js\\n at /home/me/projects/example/index.js","querySql":"SELECTT * FROM \\"test\\" WHERE id = $1;","queryArgs":[12]}\n')
t.teardown(() => {
Loading