Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed May 22, 2021
2 parents 75a54cf + 8440847 commit 3c0613a
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
directory: '/'
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: npm
directory: "/"
directory: '/'
schedule:
interval: daily
open-pull-requests-limit: 10
14 changes: 10 additions & 4 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
name: Benchmarks
on:
- push
- pull_request
push:
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'

jobs:
benchmark_current:
name: benchmark current
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v2.3.4
with:
ref: ${{ github.base_ref }}
- name: Setup Node
Expand All @@ -31,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v2.3.4
- name: Setup Node
uses: actions/setup-node@v2.1.5
with:
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: CI
on:
push:
paths-ignore:
- "docs/**"
- "*.md"
- 'docs/**'
- '*.md'
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
- 'docs/**'
- '*.md'
jobs:
test:
name: ${{ matrix.node-version }} ${{ matrix.os }}
Expand All @@ -16,9 +16,9 @@ jobs:
fail-fast: false
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]
node-version: [12, 14]
node-version: [12, 14, 16]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.3.4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.1.5
with:
Expand Down Expand Up @@ -49,6 +49,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: fastify/github-action-merge-dependabot@v2.0.0
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
with:
github-token: ${{secrets.github_token}}
github-token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,21 @@ logger.on('level-change', (lvl, val, prevLvl, prevVal) => {
logger.level = 'trace' // trigger event
```

Please note that due to a [known bug](https://github.com/pinojs/pino/issues/1006), every `logger.child()` call will
fire a `level-change` event. These events can be ignored by writing an event handler like:

```js
const logger = require('pino')()
logger.on('level-change', function (lvl, val, prevLvl, prevVal) {
if (logger !== this) {
return
}
console.log('%s (%d) was changed to %s (%d)', prevLvl, prevVal, lvl, val)
})
logger.child({}); // trigger an event by creating a child instance, notice no console.log
logger.level = 'trace' // trigger event using actual value change, notice console.log
```

<a id="version"></a>
### `logger.version` (String)

Expand Down
2 changes: 2 additions & 0 deletions docs/benchmarks.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Benchmarks

The following values show the time spent to call each function 100000 times.

`pino.info('hello world')`:

```
Expand Down
5 changes: 3 additions & 2 deletions docs/redaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
> Redaction is not supported in the browser [#670](https://github.com/pinojs/pino/issues/670)
To redact sensitive information, supply paths to keys that hold sensitive data
using the `redact` option:
using the `redact` option. Note that paths which contain hypens need to use
brackets in order to access the hyphenated property:

```js
const logger = require('.')({
redact: ['key', 'path.to.key', 'stuff.thats[*].secret']
redact: ['key', 'path.to.key', 'stuff.thats[*].secret', 'path["with-hyphen"]']
})

logger.info({
Expand Down
5 changes: 4 additions & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ function getPrettyStream (opts, prettifier, dest, instance) {
prettyFactory.asMetaWrapper = prettifierMetaWrapper
return prettifierMetaWrapper(prettyFactory(opts), dest, opts)
} catch (e) {
throw Error('Missing `pino-pretty` module: `pino-pretty` must be installed separately')
if (e.message.startsWith("Cannot find module 'pino-pretty'")) {
throw Error('Missing `pino-pretty` module: `pino-pretty` must be installed separately')
};
throw e
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pino",
"version": "6.11.2",
"version": "6.11.3",
"description": "super fast, all natural json logger",
"main": "pino.js",
"browser": "./browser.js",
Expand Down
11 changes: 2 additions & 9 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,19 +617,12 @@ test('fast-safe-stringify must be used when interpolating', async (t) => {
t.equal(msg, 'test {"a":{"b":{"c":"[Circular]"}}}')
})

test('throws when setting useOnlyCustomLevels without customLevels', async ({ equal, throws }) => {
test('throws when setting useOnlyCustomLevels without customLevels', async ({ throws }) => {
throws(() => {
pino({
useOnlyCustomLevels: true
})
})
try {
pino({
useOnlyCustomLevels: true
})
} catch ({ message }) {
equal(message, 'customLevels is required if useOnlyCustomLevels is set true')
}
}, 'customLevels is required if useOnlyCustomLevels is set true')
})

test('correctly log Infinity', async (t) => {
Expand Down
62 changes: 8 additions & 54 deletions test/custom-levels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test('customLevels property child bindings does not get logged', async ({ equal
equal(customLevels, undefined)
})

test('throws when specifying pre-existing parent labels via child bindings', async ({ equal, throws }) => {
test('throws when specifying pre-existing parent labels via child bindings', async ({ throws }) => {
const stream = sink()
throws(() => pino({
customLevels: {
Expand All @@ -135,24 +135,10 @@ test('throws when specifying pre-existing parent labels via child bindings', asy
customLevels: {
foo: 45
}
})
)
try {
pino({
customLevels: {
foo: 35
}
}, stream).child({
customLevels: {
foo: 45
}
})
} catch ({ message }) {
equal(message, 'levels cannot be overridden')
}
}), 'levels cannot be overridden')
})

test('throws when specifying pre-existing parent values via child bindings', async ({ equal, throws }) => {
test('throws when specifying pre-existing parent values via child bindings', async ({ throws }) => {
const stream = sink()
throws(() => pino({
customLevels: {
Expand All @@ -162,55 +148,23 @@ test('throws when specifying pre-existing parent values via child bindings', asy
customLevels: {
bar: 35
}
})
)
try {
pino({
customLevels: {
foo: 35
}
}, stream).child({
customLevels: {
bar: 35
}
})
} catch ({ message }) {
equal(message, 'pre-existing level values cannot be used for new levels')
}
}), 'pre-existing level values cannot be used for new levels')
})

test('throws when specifying core values via child bindings', async ({ equal, throws }) => {
test('throws when specifying core values via child bindings', async ({ throws }) => {
const stream = sink()
throws(() => pino(stream).child({
customLevels: {
foo: 30
}
})
)
try {
pino(stream).child({
customLevels: {
foo: 30
}
})
} catch ({ message }) {
equal(message, 'pre-existing level values cannot be used for new levels')
}
}), 'pre-existing level values cannot be used for new levels')
})

test('throws when useOnlyCustomLevels is set true without customLevels', async ({ equal, throws }) => {
test('throws when useOnlyCustomLevels is set true without customLevels', async ({ throws }) => {
const stream = sink()
throws(() => pino({
useOnlyCustomLevels: true
}, stream)
)
try {
pino({
useOnlyCustomLevels: true
}, stream)
} catch ({ message }) {
equal(message, 'customLevels is required if useOnlyCustomLevels is set true')
}
}, stream), 'customLevels is required if useOnlyCustomLevels is set true')
})

test('custom level on one instance does not affect other instances', async ({ equal }) => {
Expand Down
34 changes: 5 additions & 29 deletions test/levels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ test('setting levelKey does not affect labels when told to', async ({ equal }) =
instance.info('hello world')
})

test('throws when creating a default label that does not exist in logger levels', async ({ equal, throws }) => {
test('throws when creating a default label that does not exist in logger levels', async ({ throws }) => {
const defaultLevel = 'foo'
throws(() => {
pino({
Expand All @@ -387,17 +387,10 @@ test('throws when creating a default label that does not exist in logger levels'
},
level: defaultLevel
})
})
try {
pino({
level: defaultLevel
})
} catch ({ message }) {
equal(message, `default level:${defaultLevel} must be included in custom levels`)
}
}, `default level:${defaultLevel} must be included in custom levels`)
})

test('throws when creating a default value that does not exist in logger levels', async ({ equal, throws }) => {
test('throws when creating a default value that does not exist in logger levels', async ({ throws }) => {
const defaultLevel = 15
throws(() => {
pino({
Expand All @@ -406,14 +399,7 @@ test('throws when creating a default value that does not exist in logger levels'
},
level: defaultLevel
})
})
try {
pino({
level: defaultLevel
})
} catch ({ message }) {
equal(message, `default level:${defaultLevel} must be included in custom levels`)
}
}, `default level:${defaultLevel} must be included in custom levels`)
})

test('throws when creating a default value that does not exist in logger levels', async ({ equal, throws }) => {
Expand All @@ -424,17 +410,7 @@ test('throws when creating a default value that does not exist in logger levels'
},
useOnlyCustomLevels: true
})
})
try {
pino({
customLevels: {
foo: 5
},
useOnlyCustomLevels: true
})
} catch ({ message }) {
equal(message, 'default level:info must be included in custom levels')
}
}, 'default level:info must be included in custom levels')
})

test('passes when creating a default value that exists in logger levels', async ({ equal, throws }) => {
Expand Down
12 changes: 6 additions & 6 deletions test/pretty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ test('does not throw error when enabled with stream specified', async ({ doesNot
doesNotThrow(() => pino({ prettyPrint: true }, process.stdout))
})

test('throws when prettyPrint is true but pino-pretty module is not installed', async ({ throws, equal }) => {
test('throws when prettyPrint is true but pino-pretty module is not installed', async ({ throws }) => {
// pino pretty *is* installed, and probably also cached, so rather than
// messing with the filesystem the simplest way to generate a not found
// error is to simulate it:
const prettyFactory = require('pino-pretty')
require.cache[require.resolve('pino-pretty')].exports = () => {
throw Error('Cannot find module \'pino-pretty\'')
}
throws(() => pino({ prettyPrint: true }))
try { pino({ prettyPrint: true }) } catch ({ message }) {
equal(message, 'Missing `pino-pretty` module: `pino-pretty` must be installed separately')
}

throws(() => pino({ prettyPrint: true }), 'Missing `pino-pretty` module: `pino-pretty` must be installed separately')
require.cache[require.resolve('pino-pretty')].exports = prettyFactory
})

test('throws when prettyPrint has invalid options', async ({ throws }) => {
throws(() => pino({ prettyPrint: { ignore: ['hostname'] } }), 'opts.ignore.split is not a function')
})

test('can send pretty print to custom stream', async ({ equal }) => {
const dest = new Writable({
objectMode: true,
Expand Down

0 comments on commit 3c0613a

Please sign in to comment.