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 7.8.0 to 7.8.1

66

docs/api.md

@@ -33,2 +33,8 @@ # API

* [pino.version](#pino-version)
* [Interfaces](#interfaces)
* [MultiStreamRes](#multistreamres)
* [StreamEntry](#streamentry)
* [DestinationStream](#destinationstream)
* [Types](#types)
* [Level](#level-1)

@@ -291,2 +297,4 @@ <a id="export"></a>

ps: The log level cannot be customized when using multiple transports
```js

@@ -1169,5 +1177,6 @@ const formatters = {

### `pino.multistream(options) => Stream`
### `pino.multistream(streamsArray, opts) => MultiStreamRes`
Create a stream composed by multiple destination streams:
Create a stream composed by multiple destination streams and returns an
object implementing the [MultiStreamRes](#multistreamres) interface.

@@ -1278,1 +1287,54 @@ ```js

* See [`logger.version`](#version)
## Interfaces
<a id="pino-multistreamres"></a>
### `MultiStreamRes`
Properties:
* `write(data)`
- `data` Object | string
- Returns: void
Write `data` onto the streams held by the current instance.
* `add(dest)`
- `dest` [StreamEntry](#streamentry) | [DestinationStream](#destinationstream)
- Returns: [MultiStreamRes](#multistreamres)
Add `dest` stream to the array of streams of the current instance.
* `flushSync()`
- Returns: `undefined`
Call `flushSync` on each stream held by the current instance.
* `minLevel`
- number
The minimum level amongst all the streams held by the current instance.
* `streams`
- Returns: [StreamEntry[]](#streamentry)
The array of streams currently held by the current instance.
* `clone(level)`
- `level` [Level](#level-1)
- Returns: [MultiStreamRes](#multistreamres)
Returns a cloned object of the current instance but with the the provided `level`.
### `StreamEntry`
Properties:
* `stream`
- DestinationStream
* `level`
- Optional: [Level](#level-1)
### `DestinationStream`
Properties:
* `write(msg)`
- `msg` string
## Types
### `Level`
* Values: `"fatal"` | `"error"` | `"warn"` | `"info"` | `"debug"` | `"trace"`

@@ -74,1 +74,2 @@ # Pino Ecosystem

+ [`pino-dev`](https://github.com/dnjstrom/pino-dev): simple prettifier for pino with built-in support for common ecosystem packages.
+ [`@newrelic/pino-enricher`](https://github.com/newrelic/newrelic-node-log-extensions/blob/main/packages/pino-log-enricher): a log customization to add New Relic context to use [Logs In Context](https://docs.newrelic.com/docs/logs/logs-context/logs-in-context/)

42

lib/multistream.js

@@ -9,5 +9,6 @@ 'use strict'

const DEFAULT_INFO_LEVEL = levels.info
function multistream (streamsArray, opts) {
let counter = 0
streamsArray = streamsArray || []

@@ -81,18 +82,35 @@ opts = opts || { dedupe: false }

function add (dest) {
if (!dest) {
return res
}
// Check that dest implements either StreamEntry or DestinationStream
const isStream = typeof dest.write === 'function' || dest.stream
const stream_ = dest.write ? dest : dest.stream
// This is necessary to provide a meaningful error message, otherwise it throws somewhere inside write()
if (!isStream) {
throw Error('stream object needs to implement either StreamEntry or DestinationStream interface')
}
const { streams } = this
if (typeof dest.write === 'function') {
return add.call(this, { stream: dest })
} else if (typeof dest.levelVal === 'number') {
return add.call(this, Object.assign({}, dest, { level: dest.levelVal, levelVal: undefined }))
let level
if (typeof dest.levelVal === 'number') {
level = dest.levelVal
} else if (typeof dest.level === 'string') {
return add.call(this, Object.assign({}, dest, { level: levels[dest.level] }))
} else if (typeof dest.level !== 'number') {
// we default level to 'info'
dest = Object.assign({}, dest, { level: 30 })
level = levels[dest.level]
} else if (typeof dest.level === 'number') {
level = dest.level
} else {
dest = Object.assign({}, dest)
level = DEFAULT_INFO_LEVEL
}
dest.id = counter++
streams.unshift(dest)
const dest_ = {
stream: stream_,
level,
levelVal: undefined,
id: counter++
}
streams.unshift(dest_)
streams.sort(compareByLevel)

@@ -99,0 +117,0 @@

@@ -412,2 +412,5 @@ 'use strict'

}
if (opts.transport.targets && opts.transport.targets.length && opts.formatters && typeof opts.formatters.level === 'function') {
throw Error('option.transport.targets do not allow custom level formatters')
}
stream = transport({ caller, ...opts.transport })

@@ -414,0 +417,0 @@ }

{
"name": "pino",
"version": "7.8.0",
"version": "7.8.1",
"description": "super fast, all natural json logger",

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

"strip-ansi": "^6.0.0",
"tap": "^15.0.1",
"tap": "^16.0.0",
"tape": "^5.0.0",

@@ -99,0 +99,0 @@ "through2": "^4.0.0",

@@ -264,6 +264,6 @@ // Type definitions for pino 7.0

write: (data: any) => void,
add: (dest: Record<string, any>) => MultiStreamRes,
add: (dest: StreamEntry | DestinationStream) => MultiStreamRes,
flushSync: () => void,
minLevel: number,
streams: ({ stream: DestinationStream, level: number, id: number })[],
streams: StreamEntry[],
clone(level: Level): MultiStreamRes,

@@ -270,0 +270,0 @@ }

@@ -338,1 +338,28 @@ 'use strict'

})
test('throws when custom level formatter is used with transport.targets', async ({ throws }) => {
const destination = join(
os.tmpdir(),
'_' + Math.random().toString(36).substr(2, 9)
)
throws(() => {
pino({
formatters: {
level (label) {
return label
}
},
transport: {
targets: [
{
target: 'pino/file',
options: { destination }
}
]
}
}
)
},
Error('option.transport.targets do not allow custom level formatters'))
})

@@ -484,3 +484,3 @@ 'use strict'

test('add a stream', function (t) {
test('one stream', function (t) {
let messageCount = 0

@@ -501,2 +501,39 @@ const stream = writeStream(function (data, enc, cb) {

test('add a stream', function (t) {
let messageCount = 0
const stream = writeStream(function (data, enc, cb) {
messageCount += 1
cb()
})
const log = pino({
level: 'trace'
}, multistream().add(stream))
log.info('info stream')
log.debug('debug stream')
log.fatal('fatal stream')
t.equal(messageCount, 2)
t.end()
})
test('multistream.add throws if not a stream', function (t) {
try {
pino({
level: 'trace'
}, multistream().add({}))
} catch (_) {
t.end()
}
})
test('multistream throws if not a stream', function (t) {
try {
pino({
level: 'trace'
}, multistream({}))
} catch (_) {
t.end()
}
})
test('flushSync', function (t) {

@@ -503,0 +540,0 @@ const tmp = join(

@@ -24,3 +24,4 @@ import { expectType } from 'tsd'

expectType<pino.MultiStreamRes>(pino.multistream(streams, { dedupe: true }))
expectType<pino.MultiStreamRes>(pino.multistream(streams[0]).add(streams[1]))
expectType<pino.MultiStreamRes>(multistream(process.stdout));
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