Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino

Package Overview
Dependencies
Maintainers
4
Versions
311
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino - npm Package Compare versions

Comparing version 8.15.7 to 8.16.0

6

docs/api.md

@@ -967,3 +967,3 @@ # API

<a id="flush"></a>
### `logger.flush()`
### `logger.flush([cb])`

@@ -973,3 +973,3 @@ Flushes the content of the buffer when using `pino.destination({

This is an asynchronous, fire and forget, operation.
This is an asynchronous, best used as fire and forget, operation.

@@ -983,2 +983,4 @@ The use case is primarily for asynchronous logging, which may buffer

If there is a need to wait for the logs to be flushed, a callback should be used.
* See [`destination` parameter](#destination)

@@ -985,0 +987,0 @@ * See [Asynchronous Logging ⇗](/docs/asynchronous.md)

'use strict'
module.exports = { version: '8.15.7' }
module.exports = { version: '8.16.0' }

@@ -222,5 +222,12 @@ 'use strict'

function flush () {
function flush (cb) {
if (cb != null && typeof cb !== 'function') {
throw Error('callback must be a function')
}
const stream = this[streamSym]
if ('flush' in stream) stream.flush(noop)
if ('flush' in stream) {
stream.flush(cb || noop)
} else if (cb) cb()
}
{
"name": "pino",
"version": "8.15.7",
"version": "8.16.0",
"description": "super fast, all natural json logger",

@@ -113,3 +113,3 @@ "main": "pino.js",

"safe-stable-stringify": "^2.3.1",
"sonic-boom": "^3.1.0",
"sonic-boom": "^3.7.0",
"thread-stream": "^2.0.0"

@@ -116,0 +116,0 @@ },

@@ -125,4 +125,5 @@ // Project: https://github.com/pinojs/pino.git, http://getpino.io

* Flushes the content of the buffer when using pino.destination({ sync: false }).
* call the callback when finished
*/
flush(): void;
flush(cb?: (err?: Error) => void): void;
}

@@ -129,0 +130,0 @@

'use strict'
const os = require('os')
const { createWriteStream } = require('fs')
const {
createWriteStream
} = require('fs')
const { readFile } = require('fs').promises
const { join } = require('path')

@@ -9,3 +12,8 @@ const { test } = require('tap')

const writer = require('flush-write-stream')
const { once, getPathToNull } = require('./helper')
const {
once,
getPathToNull,
file,
watchFileCreated
} = require('./helper')
const { promisify } = require('util')

@@ -15,3 +23,6 @@

test('asynchronous logging', async ({ equal, teardown }) => {
test('asynchronous logging', async ({
equal,
teardown
}) => {
const now = Date.now

@@ -68,3 +79,6 @@ const hostname = os.hostname

test('sync false with child', async ({ equal, teardown }) => {
test('sync false with child', async ({
equal,
teardown
}) => {
const now = Date.now

@@ -93,3 +107,5 @@ const hostname = os.hostname

const dest = createWriteStream(getPathToNull())
dest.write = function (s) { actual += s }
dest.write = function (s) {
actual += s
}
const asyncLogger = pino(dest).child({ hello: 'world' })

@@ -128,1 +144,53 @@

})
test('should still call flush callback even when does nothing with sync true (default)', (t) => {
t.plan(3)
const instance = require('..')()
instance.flush((...args) => {
t.ok('flush called')
t.same(args, [])
// next tick to make flush not called more than once
process.nextTick(() => {
t.ok('flush next tick called')
})
})
})
test('should call the flush callback when flushed the data for async logger', async (t) => {
const outputPath = file()
async function getOutputLogLines () {
return (await readFile(outputPath)).toString().trim().split('\n').map(JSON.parse)
}
const pino = require('../')
const instance = pino({}, pino.destination({
dest: outputPath,
// to make sure it does not flush on its own
minLength: 4096
}))
const flushPromise = promisify(instance.flush).bind(instance)
instance.info('hello')
await flushPromise()
await watchFileCreated(outputPath)
const [firstFlushData] = await getOutputLogLines()
t.equal(firstFlushData.msg, 'hello')
// should not flush this as no data accumulated that's bigger than min length
instance.info('world')
// Making sure data is not flushed yet
const afterLogData = await getOutputLogLines()
t.equal(afterLogData.length, 1)
await flushPromise()
// Making sure data is not flushed yet
const afterSecondFlush = (await getOutputLogLines())[1]
t.equal(afterSecondFlush.msg, 'world')
})

@@ -9,2 +9,3 @@ 'use strict'

const { watchFileCreated, file } = require('../helper')
const { promisify } = require('util')

@@ -35,1 +36,35 @@ const { pid } = process

})
test('thread-stream async flush should call the passed callback', async (t) => {
const outputPath = file()
async function getOutputLogLines () {
return (await readFile(outputPath)).toString().trim().split('\n').map(JSON.parse)
}
const transport = pino.transport({
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
options: { destination: outputPath }
})
const instance = pino(transport)
const flushPromise = promisify(instance.flush).bind(instance)
instance.info('hello')
await flushPromise()
await watchFileCreated(outputPath)
const [firstFlushData] = await getOutputLogLines()
t.equal(firstFlushData.msg, 'hello')
// should not flush this as no data accumulated that's bigger than min length
instance.info('world')
// Making sure data is not flushed yet
const afterLogData = await getOutputLogLines()
t.equal(afterLogData.length, 1)
await flushPromise()
// Making sure data is not flushed yet
const afterSecondFlush = (await getOutputLogLines())[1]
t.equal(afterSecondFlush.msg, 'world')
})

@@ -115,2 +115,3 @@ import P, { pino } from "../../";

expectType<void>(log.flush());
log.flush((err?: Error) => undefined);
log.child({ a: "property" }).info("hello child!");

@@ -117,0 +118,0 @@ log.level = "error";

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc