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.2.0
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.3.0
Choose a head ref
  • 16 commits
  • 13 files changed
  • 10 contributors

Commits on Nov 4, 2021

  1. Fixed failing test

    mcollina committed Nov 4, 2021
    Copy the full SHA
    2f57958 View commit details

Commits on Nov 16, 2021

  1. Add ability to format time and level with user-defined prettifiers (#263

    )
    
    Co-authored-by: James Sumners <james@sumners.email>
    pearofducks and jsumners authored Nov 16, 2021
    Copy the full SHA
    dcebb40 View commit details

Commits on Nov 17, 2021

  1. Copy the full SHA
    bdae36e View commit details
  2. Copy the full SHA
    36d733b View commit details

Commits on Nov 19, 2021

  1. Bump fastify/github-action-merge-dependabot from 2.4.0 to 2.6.0 (#267)

    Bumps [fastify/github-action-merge-dependabot](https://github.com/fastify/github-action-merge-dependabot) from 2.4.0 to 2.6.0.
    - [Release notes](https://github.com/fastify/github-action-merge-dependabot/releases)
    - [Commits](fastify/github-action-merge-dependabot@v2.4.0...v2.6.0)
    
    ---
    updated-dependencies:
    - dependency-name: fastify/github-action-merge-dependabot
      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 Nov 19, 2021
    Copy the full SHA
    5a5dcbc View commit details
  2. Bump tsd from 0.18.0 to 0.19.0 (#269)

    Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.18.0 to 0.19.0.
    - [Release notes](https://github.com/SamVerschueren/tsd/releases)
    - [Commits](tsdjs/tsd@v0.18.0...v0.19.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 Nov 19, 2021
    Copy the full SHA
    16d47b1 View commit details

Commits on Nov 20, 2021

  1. Copy the full SHA
    c070efb View commit details

Commits on Nov 22, 2021

  1. Copy the full SHA
    ddafa94 View commit details

Commits on Nov 23, 2021

  1. Copy the full SHA
    f96075f View commit details
  2. Copy the full SHA
    d1d0571 View commit details

Commits on Nov 30, 2021

  1. Bump fastify/github-action-merge-dependabot from 2.6.0 to 2.7.0 (#277)

    Bumps [fastify/github-action-merge-dependabot](https://github.com/fastify/github-action-merge-dependabot) from 2.6.0 to 2.7.0.
    - [Release notes](https://github.com/fastify/github-action-merge-dependabot/releases)
    - [Commits](fastify/github-action-merge-dependabot@v2.6.0...v2.7.0)
    
    ---
    updated-dependencies:
    - dependency-name: fastify/github-action-merge-dependabot
      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 Nov 30, 2021
    Copy the full SHA
    e779f2f View commit details
  2. Fixed markdown (#278)

    sleroq authored Nov 30, 2021
    Copy the full SHA
    68b3d9e View commit details

Commits on Dec 8, 2021

  1. Copy the full SHA
    eb88841 View commit details

Commits on Dec 9, 2021

  1. Bump fastify/github-action-merge-dependabot from 2.7.0 to 2.7.1 (#281)

    Bumps [fastify/github-action-merge-dependabot](https://github.com/fastify/github-action-merge-dependabot) from 2.7.0 to 2.7.1.
    - [Release notes](https://github.com/fastify/github-action-merge-dependabot/releases)
    - [Commits](fastify/github-action-merge-dependabot@v2.7.0...v2.7.1)
    
    ---
    updated-dependencies:
    - dependency-name: fastify/github-action-merge-dependabot
      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 Dec 9, 2021
    Copy the full SHA
    fd1308e View commit details

Commits on Dec 13, 2021

  1. Allow loading common js config files by default (#282)

    * Allow loading cjs files as config by default
    
    * Remove redundant joycon loader
    EchelonFour authored Dec 13, 2021
    Copy the full SHA
    4ec29b2 View commit details
  2. Bumped v7.3.0

    Signed-off-by: Matteo Collina <hello@matteocollina.com>
    mcollina committed Dec 13, 2021
    Copy the full SHA
    de1007f View commit details
Showing with 274 additions and 55 deletions.
  1. +4 −0 .github/dependabot.yml
  2. +3 −3 .github/workflows/ci.yml
  3. +51 −0 Readme.md
  4. +1 −4 bin.js
  5. +11 −4 index.d.ts
  6. +4 −9 index.js
  7. +9 −8 lib/utils.js
  8. +3 −3 package.json
  9. +121 −3 test/basic.test.js
  10. +23 −0 test/cli-rc.test.js
  11. +23 −1 test/error-objects.test.js
  12. +11 −5 test/lib/colors.test.js
  13. +10 −15 test/types/pino-pretty.test-d.ts
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@ version: 2
updates:
- package-ecosystem: github-actions
directory: '/'
ignore:
- dependency-name: 'actions/*'
update-types:
['version-update:semver-minor', 'version-update:semver-patch']
schedule:
interval: daily
open-pull-requests-limit: 10
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -21,10 +21,10 @@ jobs:
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
uses: actions/checkout@v2

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

@@ -72,6 +72,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: fastify/github-action-merge-dependabot@v2.4.0
- uses: fastify/github-action-merge-dependabot@v2.7.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
51 changes: 51 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -153,6 +153,22 @@ logger.info('hi')

See the [Options](#options) section for all possible options.

If you are using `pino-pretty` as a stream and you need to provide options to `pino`,
pass the options as the first argument and `pino-pretty` as second argument:

```js
const pino = require('pino')
const pretty = require('pino-pretty')
const stream = pretty({
prettyPrint: { colorize: true }
})
const logger = pino({ level: 'info' }, stream)

// Nothing is printed
logger.debug('hi')
```


### Handling non-serializable options

Using the new [pino v7+
@@ -226,6 +242,7 @@ for specific log properties. `customPrettifiers` is an object, where keys are
log properties that will be prettified and value is the prettify function itself.
For example, if a log line contains a `query` property,
you can specify a prettifier for it:

```js
{
customPrettifiers: {
@@ -238,13 +255,47 @@ const prettifyQuery = value => {
}
```

Additionally, `customPrettifiers` can be used to format the time and level
outputs:

```js
{
customPrettifiers: {
// The argument for this function will be the same
// string that's at the start of the log-line by default:
time: timestamp => `🕰 ${timestamp}`,

// The argument for the level-prettifier may vary depending
// on if the levelKey option is used or not.
// By default this will be the same numerics as the Pino default:
level: logLevel => `LEVEL: ${logLevel}`
}
}
```

Note that prettifiers do not include any coloring, if the stock coloring on
`level` is desired, it can be accomplished using the following:

```js
const { colorizerFactory } = require('pino-pretty')
const levelColorize = colorizerFactory(true)
const levelPrettifier = logLevel => `LEVEL: ${levelColorize(logLevel)}`
//...
{
customPrettifiers: { level: levelPrettifier }
}
```

`messageFormat` option allows you to customize the message output. A template `string` like this can define the format:

```js
{
messageFormat: '{levelLabel} - {pid} - url:{request.url}'
}
```

This option can also be defined as a `function` with this prototype:

```js
{
messageFormat: (log, messageKey, levelLabel) => {
5 changes: 1 addition & 4 deletions bin.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -19,16 +19,13 @@ const parseJSON = input => {
const joycon = new JoyCon({
parseJSON,
files: [
'pino-pretty.config.cjs',
'pino-pretty.config.js',
'.pino-prettyrc',
'.pino-prettyrc.json'
],
stopDir: path.dirname(process.cwd())
})
joycon.addLoader({
test: /\.[^.]*rc$/,
loadSync: (path) => parseJSON(fs.readFileSync(path, 'utf-8'))
})

args
.option(['c', 'colorize'], 'Force adding color sequences to the output')
15 changes: 11 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// Type definitions for pino-pretty 4.7
// Type definitions for pino-pretty 7.0
// Project: https://github.com/pinojs/pino-pretty#readme
// Definitions by: Adam Vigneaux <https://github.com/AdamVig>
// tearwyx <https://github.com/tearwyx>
// Minimum TypeScript Version: 3.0

/// <reference types="node" />

import { Transform } from 'stream';
import { OnUnknown } from 'pino-abstract-transport';

type LogDescriptor = Record<string, unknown>;

declare function PinoPretty(options: PrettyOptions_): PinoPretty.Prettifier;
declare function PinoPretty(options: PrettyOptions_): PinoPretty.PrettyStream;

interface PrettyOptions_ {
/**
@@ -121,8 +127,9 @@ interface PrettyOptions_ {
declare namespace PinoPretty {
type Prettifier = (inputData: string | object) => string;
type MessageFormatFunc = (log: LogDescriptor, messageKey: string, levelLabel: string) => string;
type PrettyOptions = PrettyOptions_
type PrettyOptions = PrettyOptions_;
type PrettyStream = Transform & OnUnknown;
}

export default PinoPretty;
export { PinoPretty, PrettyOptions_ as PrettyOptions }
export { PinoPretty, PrettyOptions_ as PrettyOptions };
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -90,9 +90,9 @@ function prettyFactory (options) {
log = filterLog(log, ignoreKeys)
}

const prettifiedLevel = prettifyLevel({ log, colorizer, levelKey })
const prettifiedLevel = prettifyLevel({ log, colorizer, levelKey, prettifier: customPrettifiers.level })
const prettifiedMetadata = prettifyMetadata({ log })
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey })
const prettifiedTime = prettifyTime({ log, translateFormat: opts.translateTime, timestampKey, prettifier: customPrettifiers.time })

let line = ''
if (opts.levelFirst && prettifiedLevel) {
@@ -146,6 +146,7 @@ function prettyFactory (options) {
ident: IDENT,
eol: EOL
})
if (singleLine) line += EOL
line += prettifiedErrorLog
} else if (!hideObject) {
const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number')
@@ -195,13 +196,6 @@ function build (opts = {}) {
sync: false
})
}
/* istanbul ignore else */
if (destination.fd === 1) {
// We cannot close the output
destination.end = function () {
this.emit('close')
}
}

source.on('unknown', function (line) {
destination.write(line + '\n')
@@ -214,4 +208,5 @@ function build (opts = {}) {

module.exports = build
module.exports.prettyFactory = prettyFactory
module.exports.colorizerFactory = colors
module.exports.default = build
17 changes: 9 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -218,14 +218,16 @@ function prettifyErrorLog ({
* @param {function} [input.colorizer] A colorizer function that accepts a level
* value and returns a colorized string. Default: a no-op colorizer.
* @param {string} [levelKey='level'] The key to find the level under.
* @param {function} [input.prettifier] A user-supplied formatter to be called instead of colorizer.
*
* @returns {undefined|string} If `log` does not have a `level` property then
* `undefined` will be returned. Otherwise, a string from the specified
* `colorizer` is returned.
*/
function prettifyLevel ({ log, colorizer = defaultColorizer, levelKey = LEVEL_KEY }) {
function prettifyLevel ({ log, colorizer = defaultColorizer, levelKey = LEVEL_KEY, prettifier }) {
if (levelKey in log === false) return undefined
return colorizer(log[levelKey])
const output = log[levelKey]
return prettifier ? prettifier(output) : colorizer(output)
}

/**
@@ -393,7 +395,7 @@ function prettifyObject ({
if (lines === undefined) return

const joinedLines = joinLinesWithIndentation({ input: lines, ident, eol })
result += `${ident}${keyName}: ${joinedLines}${eol}`
result += `${ident}${keyName}:${joinedLines.startsWith(eol) ? '' : ' '}${joinedLines}${eol}`
})
}

@@ -423,12 +425,13 @@ function prettifyObject ({
* timestamp will be prettified into a string at UTC using the default
* `DATE_FORMAT`. If a string, then `translateFormat` will be used as the format
* string to determine the output; see the `formatTime` function for details.
* @param {function} [input.prettifier] A user-supplied formatter for altering output.
*
* @returns {undefined|string} If a timestamp property cannot be found then
* `undefined` is returned. Otherwise, the prettified time is returned as a
* string.
*/
function prettifyTime ({ log, timestampKey = TIMESTAMP_KEY, translateFormat = undefined }) {
function prettifyTime ({ log, timestampKey = TIMESTAMP_KEY, translateFormat = undefined, prettifier }) {
let time = null

if (timestampKey in log) {
@@ -438,11 +441,9 @@ function prettifyTime ({ log, timestampKey = TIMESTAMP_KEY, translateFormat = un
}

if (time === null) return undefined
if (translateFormat) {
return '[' + formatTime(time, translateFormat) + ']'
}
const output = translateFormat ? formatTime(time, translateFormat) : time

return `[${time}]`
return prettifier ? prettifier(output) : `[${output}]`
}

/**
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pino-pretty",
"version": "7.2.0",
"version": "7.3.0",
"description": "Prettifier for Pino log lines",
"type": "commonjs",
"main": "index.js",
@@ -36,7 +36,7 @@
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-safe-stringify": "^2.0.7",
"joycon": "^3.0.0",
"joycon": "^3.1.1",
"pino-abstract-transport": "^0.5.0",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
@@ -53,7 +53,7 @@
"snazzy": "^9.0.0",
"standard": "^16.0.3",
"tap": "^15.0.9",
"tsd": "^0.18.0",
"tsd": "^0.19.0",
"typescript": "^4.4.3"
},
"tsd": {
Loading