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
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
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.3.0
Choose a head ref
  • 8 commits
  • 9 files changed
  • 5 contributors

Commits on Nov 15, 2021

  1. Copy the full SHA
    8fde791 View commit details
  2. Avoid duplicate action runs for eg. Dependabot

    As it pushes to a branch in the pino repo itself, unless we tell the CI jobs to only trigger `push` on the `main` branch, then it will trigger both `push` and `pull_request` on eg. the Dependabot PR:s
    voxpelli committed Nov 15, 2021
    Copy the full SHA
    7d2a9a0 View commit details
  3. Merge pull request #1220 from voxpelli/make-actions-target-branch

    Avoid duplicate action runs for eg. Dependabot
    jsumners authored Nov 15, 2021
    Copy the full SHA
    d28197f View commit details

Commits on Nov 17, 2021

  1. Copy the full SHA
    b37a947 View commit details

Commits on Nov 18, 2021

  1. Copy the full SHA
    2987244 View commit details
  2. Add node v17 to CI (#1228)

    mcollina authored Nov 18, 2021
    Copy the full SHA
    0ab984f View commit details
  3. Copy the full SHA
    bfce37c View commit details
  4. Bumped v7.3.0

    mcollina committed Nov 18, 2021
    Copy the full SHA
    1c588c4 View commit details
Showing with 125 additions and 23 deletions.
  1. +4 −0 .github/dependabot.yml
  2. +8 −6 .github/workflows/bench.yml
  3. +5 −3 .github/workflows/ci.yml
  4. +6 −6 .github/workflows/package-manager-ci.yml
  5. +22 −0 docs/transports.md
  6. +4 −1 file.js
  7. +1 −1 package.json
  8. +28 −4 test/helper.js
  9. +47 −2 test/transport/core.test.js
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
14 changes: 8 additions & 6 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Benchmarks
on:
push:
branches:
- main
paths-ignore:
- 'docs/**'
- '*.md'
@@ -15,19 +17,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2.3.5
uses: actions/checkout@v2
with:
ref: ${{ github.base_ref }}
- name: Setup Node
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Modules
run: npm i
- name: Run Benchmark
run: npm run bench | tee current.txt
- name: Upload Current Results
uses: actions/upload-artifact@v2.2.4
uses: actions/upload-artifact@v2
with:
name: current
path: current.txt
@@ -37,17 +39,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2.3.5
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install Modules
run: npm i
- name: Run Benchmark
run: npm run bench | tee branch.txt
- name: Upload Branch Results
uses: actions/upload-artifact@v2.2.4
uses: actions/upload-artifact@v2
with:
name: branch
path: branch.txt
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI
on:
push:
branches:
- main
paths-ignore:
- 'docs/**'
- '*.md'
@@ -16,11 +18,11 @@ jobs:
fail-fast: false
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]
node-version: [12, 14, 16]
node-version: [12, 14, 16, 17]
steps:
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install
12 changes: 6 additions & 6 deletions .github/workflows/package-manager-ci.yml
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@ jobs:
os: [windows-latest, ubuntu-latest]
node-version: [14]
steps:
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Use pnpm
@@ -37,9 +37,9 @@ jobs:
os: [windows-latest, ubuntu-latest]
node-version: [14]
steps:
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Use yarn
@@ -64,9 +64,9 @@ jobs:
os: [windows-latest, ubuntu-latest]
node-version: [14]
steps:
- uses: actions/checkout@v2.3.5
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Use yarn
22 changes: 22 additions & 0 deletions docs/transports.md
Original file line number Diff line number Diff line change
@@ -240,6 +240,28 @@ const transport = pino.transport({
pino(transport)
```
By default, the `pino/file` transport assumes the directory of the destination file exists. If it does not exist, the transport will throw an error when it attempts to open the file for writing. The `mkdir` option may be set to `true` to configure the transport to create the directory, if it does not exist, before opening the file for writing.
```js
const pino = require('pino')
const transport = pino.transport({
target: 'pino/file',
options: { destination: '/path/to/file', mkdir: true }
})
pino(transport)
```
By default, the `pino/file` transport appends to the destination file if it exists. The `append` option may be set to `false` to configure the transport to truncate the file upon opening it for writing.
```js
const pino = require('pino')
const transport = pino.transport({
target: 'pino/file',
options: { destination: '/path/to/file', append: false }
})
pino(transport)
```
The `options.destination` property may also be a number to represent a file descriptor. Typically this would be `1` to write to STDOUT or `2` to write to STDERR. If `options.destination` is not set, it defaults to `1` which means logs will be written to STDOUT.
The difference between using the `pino/file` transport builtin and using `pino.destination` is that `pino.destination` runs in the main thread, whereas `pino/file` sets up `pino.destination` in a worker thread.
5 changes: 4 additions & 1 deletion file.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,10 @@ const pino = require('./pino')
const { once } = require('events')

module.exports = async function (opts = {}) {
const destination = pino.destination({ dest: opts.destination || 1, sync: false })
const destOpts = { dest: opts.destination || 1, sync: false }
if (opts.append === false) destOpts.append = false
if (opts.mkdir) destOpts.mkdir = true
const destination = pino.destination(destOpts)
await once(destination, 'ready')
return destination
}
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": "7.2.0",
"version": "7.3.0",
"description": "super fast, all natural json logger",
"main": "pino.js",
"type": "commonjs",
32 changes: 28 additions & 4 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
const os = require('os')
const writer = require('flush-write-stream')
const split = require('split2')
const { existsSync, statSync } = require('fs')
const { existsSync, readFileSync, statSync } = require('fs')
const pid = process.pid
const hostname = os.hostname()

@@ -59,18 +59,42 @@ function watchFileCreated (filename) {
const threshold = TIMEOUT / INTERVAL
let counter = 0
const interval = setInterval(() => {
const exists = existsSync(filename)
// On some CI runs file is created but not filled
if (existsSync(filename) && statSync(filename).size !== 0) {
if (exists && statSync(filename).size !== 0) {
clearInterval(interval)
resolve()
} else if (counter <= threshold) {
counter++
} else {
clearInterval(interval)
reject(new Error(`${filename} was not created.`))
reject(new Error(
`${filename} hasn't been created within ${TIMEOUT} ms. ` +
(exists ? 'File exist, but still empty.' : 'File not yet created.')
))
}
}, INTERVAL)
})
}

module.exports = { getPathToNull, sink, check, once, sleep, watchFileCreated, isWin, isYarnPnp }
function watchForWrite (filename, testString) {
return new Promise((resolve, reject) => {
const TIMEOUT = 2000
const INTERVAL = 100
const threshold = TIMEOUT / INTERVAL
let counter = 0
const interval = setInterval(() => {
if (readFileSync(filename).includes(testString)) {
clearInterval(interval)
resolve()
} else if (counter <= threshold) {
counter++
} else {
clearInterval(interval)
reject(new Error(`'${testString}' hasn't been written to ${filename} within ${TIMEOUT} ms.`))
}
}, INTERVAL)
})
}

module.exports = { getPathToNull, sink, check, once, sleep, watchFileCreated, watchForWrite, isWin, isYarnPnp }
49 changes: 47 additions & 2 deletions test/transport/core.test.js
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
const os = require('os')
const { join } = require('path')
const { once } = require('events')
const { readFile } = require('fs').promises
const { watchFileCreated } = require('../helper')
const { readFile, writeFile } = require('fs').promises
const { watchFileCreated, watchForWrite } = require('../helper')
const { test } = require('tap')
const pino = require('../../')
const url = require('url')
@@ -279,6 +279,51 @@ test('pino.transport with target pino/file', async ({ same, teardown }) => {
})
})

test('pino.transport with target pino/file and mkdir option', async ({ same, teardown }) => {
const folder = '_' + Math.random().toString(36).substr(2, 9)
const destination = join(os.tmpdir(), folder, folder)
const transport = pino.transport({
target: 'pino/file',
options: { destination, mkdir: true }
})
teardown(transport.end.bind(transport))
const instance = pino(transport)
instance.info('hello')
await watchFileCreated(destination)
const result = JSON.parse(await readFile(destination))
delete result.time
same(result, {
pid,
hostname,
level: 30,
msg: 'hello'
})
})

test('pino.transport with target pino/file and append option', async ({ same, teardown }) => {
const destination = join(
os.tmpdir(),
'_' + Math.random().toString(36).substr(2, 9)
)
await writeFile(destination, JSON.stringify({ pid, hostname, time: Date.now(), level: 30, msg: 'hello' }))
const transport = pino.transport({
target: 'pino/file',
options: { destination, append: false }
})
teardown(transport.end.bind(transport))
const instance = pino(transport)
instance.info('goodbye')
await watchForWrite(destination, '"goodbye"')
const result = JSON.parse(await readFile(destination))
delete result.time
same(result, {
pid,
hostname,
level: 30,
msg: 'goodbye'
})
})

test('pino.transport with target pino-pretty', async ({ match, teardown }) => {
const destination = join(
os.tmpdir(),