Socket
Socket
Sign inDemoInstall

pino

Package Overview
Dependencies
Maintainers
4
Versions
310
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 6.13.4 to 6.14.0

test/mixin-merge-strategy.test.js

67

docs/api.md

@@ -97,2 +97,3 @@ # API

<a id="opt-mixin"></a>
#### `mixin` (Function):

@@ -121,3 +122,4 @@

The result of `mixin()` is supposed to be a _new_ object. For performance reason, the object returned by `mixin()` will be mutated by pino.
In the following example, passing `mergingObject` argument to the first `info` call will mutate the global `mixin` object:
In the following example, passing `mergingObject` argument to the first `info` call will mutate the global `mixin` object by default
(* See [`mixinMergeStrategy` option](#opt-mixin-merge-strategy)):
```js

@@ -146,2 +148,65 @@ const mixin = {

<a id="opt-mixin-merge-strategy"></a>
#### `mixinMergeStrategy` (Function):
Default: `undefined`
If provided, the `mixinMergeStrategy` function is called each time one of the active
logging methods is called. The first parameter is the value `mergeObject` or an empty object,
the second parameter is the value resulting from `mixin()` (* See [`mixin` option](#opt-mixin) or an empty object.
The function must synchronously return an object.
```js
// Default strategy, `mergeObject` has priority
const logger = pino({
mixin() {
return { tag: 'docker' }
},
// mixinMergeStrategy(mergeObject, mixinObject) {
// return Object.assign(mixinMeta, mergeObject)
// }
})
logger.info({
tag: 'local'
}, 'Message')
// {"level":30,"time":1591195061437,"pid":16012,"hostname":"x","tag":"local","msg":"Message"}
```
```js
// Custom mutable strategy, `mixin` has priority
const logger = pino({
mixin() {
return { tag: 'k8s' }
},
mixinMergeStrategy(mergeObject, mixinObject) {
return Object.assign(mergeObject, mixinObject)
}
})
logger.info({
tag: 'local'
}, 'Message')
// {"level":30,"time":1591195061437,"pid":16012,"hostname":"x","tag":"k8s","msg":"Message"}
```
```js
// Custom immutable strategy, `mixin` has priority
const logger = pino({
mixin() {
return { tag: 'k8s' }
},
mixinMergeStrategy(mergeObject, mixinObject) {
return Object.assign({}, mergeObject, mixinObject)
}
})
logger.info({
tag: 'local'
}, 'Message')
// {"level":30,"time":1591195061437,"pid":16012,"hostname":"x","tag":"k8s","msg":"Message"}
```
<a id="opt-redact"></a>

@@ -148,0 +213,0 @@ #### `redact` (Array | Object):

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

writeSym,
mixinMergeStrategySym,
timeSym,

@@ -181,5 +182,18 @@ timeSliceIndexSym,

/**
* Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
* Fields from `mergeObject` have higher priority in this strategy.
*
* @param {Object} mergeObject The object a user has supplied to the logging function.
* @param {Object} mixinObject The result of the `mixin` method.
* @return {Object}
*/
function defaultMixinMergeStrategy (mergeObject, mixinObject) {
return Object.assign(mixinObject, mergeObject)
}
function write (_obj, msg, num) {
const t = this[timeSym]()
const mixin = this[mixinSym]
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy
const objError = _obj instanceof Error

@@ -191,3 +205,3 @@ let obj

} else {
obj = Object.assign(mixin ? mixin(_obj) : {}, _obj)
obj = mixinMergeStrategy(_obj, mixin ? mixin(_obj) : {})
if (!msg && objError) {

@@ -194,0 +208,0 @@ msg = _obj.message

4

lib/symbols.js

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

const nestedKeySym = Symbol('pino.nestedKey')
const mixinMergeStrategySym = Symbol('pino.mixinMergeStrategy')

@@ -64,3 +65,4 @@ const wildcardFirstSym = Symbol('pino.wildcardFirst')

formattersSym,
hooksSym
hooksSym,
mixinMergeStrategySym
}
{
"name": "pino",
"version": "6.13.4",
"version": "6.14.0",
"description": "super fast, all natural json logger",

@@ -5,0 +5,0 @@ "main": "pino.js",

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

const { version } = require('./lib/meta')
const { mixinMergeStrategySym } = require('./lib/symbols')
const {

@@ -95,2 +96,3 @@ chindingsSym,

mixin,
mixinMergeStrategy,
useOnlyCustomLevels,

@@ -178,2 +180,3 @@ formatters,

[mixinSym]: mixin,
[mixinMergeStrategySym]: mixinMergeStrategy,
[chindingsSym]: chindings,

@@ -180,0 +183,0 @@ [formattersSym]: allFormatters,

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