Skip to content

Commit

Permalink
Merge branch 'master' into disable-finalizationregistry-withnode-code…
Browse files Browse the repository at this point in the history
…-cov

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Oct 3, 2023
2 parents 45a4173 + dcb5e1b commit bdf6a13
Show file tree
Hide file tree
Showing 61 changed files with 3,171 additions and 1,865 deletions.
8 changes: 8 additions & 0 deletions .eslintrc
@@ -0,0 +1,8 @@
{
"extends": [
"standard"
],
"rules": {
"no-var": "off"
}
}
32 changes: 2 additions & 30 deletions .github/workflows/ci.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

Expand All @@ -44,7 +44,7 @@ jobs:
os: [ubuntu-latest]
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

Expand All @@ -65,34 +65,6 @@ jobs:
- name: Run tests
run: npm run ci

- name: Coveralls Parallel
id: coveralls-parallel
uses: coverallsapp/github-action@v2.2.0
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: test
runs-on: ubuntu-latest
if: needs.test.outputs.COVERALLS != 'failure'
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

automerge:
name: Automerge Dependabot PRs
if: >
Expand Down
5 changes: 0 additions & 5 deletions .taprc

This file was deleted.

8 changes: 8 additions & 0 deletions .taprc.yaml
@@ -0,0 +1,8 @@
coverage: true
coverage-map: 'coverage-map.js'

reporter: terse

files:
- 'lib/**/*.test.js'
- 'test/**/*.test.js'
16 changes: 13 additions & 3 deletions Readme.md
Expand Up @@ -298,8 +298,8 @@ const prettifyQuery = value => {
}
```

Additionally, `customPrettifiers` can be used to format the `time`, `hostname`, `pid`, `name`, `caller` and `level`
outputs:
Additionally, `customPrettifiers` can be used to format the `time`, `hostname`,
`pid`, `name`, `caller` and `level` outputs:

```js
{
Expand Down Expand Up @@ -335,14 +335,24 @@ const levelPrettifier = logLevel => `LEVEL: ${levelColorize(logLevel)}`
}
```

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

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

In addition to this, if / end statement blocks can also be specified.
Else statements and nested conditions are not supported.

```js
{
messageFormat: '{levelLabel} - {if pid}{pid} - {end}url:{req.url}'
}
```

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

```js
Expand Down
105 changes: 105 additions & 0 deletions benchmark.js
@@ -0,0 +1,105 @@
'use strict'

// We do not expect amazing numbers from `pino-pretty` as the whole purpose
// of the module is a very slow operation. However, this benchmark should give
// us some guidance on how features, or code changes, will affect the
// performance of the module.

const bench = require('fastbench')
const {
prettyFactory
} = require('./index')

const max = 10
const tstampMillis = 1693401358754

/* eslint-disable no-var */
const run = bench([
function basicLog (cb) {
const pretty = prettyFactory({})
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","msg":"benchmark","foo":"foo","bar":{"bar":"bar"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function objectLog (cb) {
const pretty = prettyFactory({})
const input = {
time: tstampMillis,
pid: 1,
hostname: 'foo',
msg: 'benchmark',
foo: 'foo',
bar: { bar: 'bar' }
}
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function coloredLog (cb) {
const pretty = prettyFactory({ colorize: true })
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","msg":"benchmark","foo":"foo","bar":{"bar":"bar"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function customPrettifiers (cb) {
const pretty = prettyFactory({
customPrettifiers: {
time (tstamp) {
return tstamp
},
pid () {
return ''
}
}
})
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","msg":"benchmark","foo":"foo","bar":{"bar":"bar"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function logWithErrorObject (cb) {
const pretty = prettyFactory({})
const err = Error('boom')
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","msg":"benchmark","foo":"foo","bar":{"bar":"bar"},"err":{"message":"${err.message}","stack":"${err.stack}"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function logRemappedMsgErrKeys (cb) {
const pretty = prettyFactory({
messageKey: 'message',
errorLikeObjectKeys: ['myError']
})
const err = Error('boom')
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","message":"benchmark","foo":"foo","bar":{"bar":"bar"},"myError":{"message":"${err.message}","stack":"${err.stack}"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
},

function messageFormatString (cb) {
const pretty = prettyFactory({
messageFormat: '{levelLabel}{if pid} {pid} - {end}{msg}'
})
const input = `{"time":${tstampMillis},"pid":1,"hostname":"foo","msg":"benchmark","foo":"foo","bar":{"bar":"bar"}}\n`
for (var i = 0; i < max; i += 1) {
pretty(input)
}
setImmediate(cb)
}
], 10000)

run(run)
9 changes: 9 additions & 0 deletions coverage-map.js
@@ -0,0 +1,9 @@
'use strict'

module.exports = testFile => {
// Ignore coverage on files that do not have a direct corollary.
if (testFile.startsWith('test/')) return false

// Indicate the matching name, sans '.test.js', should be checked for coverage.
return testFile.replace(/\.test\.js$/, '.js')
}

0 comments on commit bdf6a13

Please sign in to comment.