Comparing version 8.3.1 to 8.4.0
@@ -384,2 +384,3 @@ # API | ||
the object is an instance of `Error`, e.g. `logger.info(new Error('kaboom'))`. | ||
See `errorKey` option to change `err` namespace. | ||
@@ -438,2 +439,9 @@ * See [pino.stdSerializers](#pino-stdserializers) | ||
<a id=opt-messagekey></a> | ||
#### `errorKey` (String) | ||
Default: `'err'` | ||
The string key for the 'error' in the JSON object. | ||
<a id=opt-nestedkey></a> | ||
@@ -608,2 +616,5 @@ #### `nestedKey` (String) | ||
Options `serializers` and `errorKey` could be used at instantiation time to change the namespace | ||
from `err` to another string as preferred. | ||
<a id="message"></a> | ||
@@ -631,3 +642,3 @@ #### `message` (String) | ||
If no `message` parameter is provided, and the `mergingObject` is of type `Error` or it has a property named `err`, the | ||
`message` parameter is set to the `message` value of the error. | ||
`message` parameter is set to the `message` value of the error. See option `errorKey` if you want to change the namespace. | ||
@@ -696,2 +707,5 @@ The `messageKey` option can be used at instantiation time to change the namespace | ||
Options `serializers` and `errorKey` could be used at instantiation time to change the namespace | ||
from `err` to another string as preferred. | ||
> ## Note | ||
@@ -698,0 +712,0 @@ > This section describes the default configuration. The error serializer can be |
'use strict' | ||
module.exports = { version: '8.3.1' } | ||
module.exports = { version: '8.4.0' } |
@@ -50,6 +50,14 @@ 'use strict' | ||
const { streams } = this | ||
// for handling situation when several streams has the same level | ||
let recordedLevel = 0 | ||
let stream | ||
for (let i = 0; i < streams.length; i++) { | ||
// if dedupe set to true we send logs to the stream with the highest level | ||
// therefore, we have to change sorting order | ||
for (let i = initLoopVar(streams.length, opts.dedupe); checkLoopVar(i, streams.length, opts.dedupe); i = adjustLoopVar(i, opts.dedupe)) { | ||
dest = streams[i] | ||
if (dest.level <= level) { | ||
if (recordedLevel !== 0 && recordedLevel !== dest.level) { | ||
break | ||
} | ||
stream = dest.stream | ||
@@ -64,6 +72,7 @@ if (stream[metadata]) { | ||
} | ||
if (!opts.dedupe || dest.level === level) { | ||
stream.write(data) | ||
stream.write(data) | ||
if (opts.dedupe) { | ||
recordedLevel = dest.level | ||
} | ||
} else { | ||
} else if (!opts.dedupe) { | ||
break | ||
@@ -158,2 +167,14 @@ } | ||
function initLoopVar (length, dedupe) { | ||
return dedupe ? length - 1 : 0 | ||
} | ||
function adjustLoopVar (i, dedupe) { | ||
return dedupe ? i - 1 : i + 1 | ||
} | ||
function checkLoopVar (i, length, dedupe) { | ||
return dedupe ? i >= 0 : i < length | ||
} | ||
module.exports = multistream |
@@ -22,2 +22,3 @@ 'use strict' | ||
formattersSym, | ||
errorKeySym, | ||
useOnlyCustomLevelsSym, | ||
@@ -178,2 +179,3 @@ needsMetadataGsym, | ||
const mixin = this[mixinSym] | ||
const errorKey = this[errorKeySym] | ||
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy | ||
@@ -185,3 +187,3 @@ let obj | ||
} else if (_obj instanceof Error) { | ||
obj = { err: _obj } | ||
obj = { [errorKey]: _obj } | ||
if (msg === undefined) { | ||
@@ -192,4 +194,4 @@ msg = _obj.message | ||
obj = _obj | ||
if (msg === undefined && _obj.err) { | ||
msg = _obj.err.message | ||
if (msg === undefined && _obj[errorKey]) { | ||
msg = _obj[errorKey].message | ||
} | ||
@@ -196,0 +198,0 @@ } |
@@ -26,2 +26,3 @@ 'use strict' | ||
const messageKeySym = Symbol('pino.messageKey') | ||
const errorKeySym = Symbol('pino.errorKey') | ||
const nestedKeySym = Symbol('pino.nestedKey') | ||
@@ -61,2 +62,3 @@ const nestedKeyStrSym = Symbol('pino.nestedKeyStr') | ||
messageKeySym, | ||
errorKeySym, | ||
nestedKeySym, | ||
@@ -63,0 +65,0 @@ wildcardFirstSym, |
{ | ||
"name": "pino", | ||
"version": "8.3.1", | ||
"version": "8.4.0", | ||
"description": "super fast, all natural json logger", | ||
@@ -5,0 +5,0 @@ "main": "pino.js", |
@@ -379,2 +379,6 @@ // Type definitions for pino 7.0 | ||
/** | ||
* The string key for the 'error' in the JSON object. Default: "err". | ||
*/ | ||
errorKey?: string; | ||
/** | ||
* The string key to place any logged object under. | ||
@@ -686,2 +690,3 @@ */ | ||
readonly messageKeySym: unique symbol; | ||
readonly errorKeySym: unique symbol; | ||
readonly nestedKeySym: unique symbol; | ||
@@ -688,0 +693,0 @@ readonly wildcardFirstSym: unique symbol; |
@@ -36,2 +36,3 @@ 'use strict' | ||
messageKeySym, | ||
errorKeySym, | ||
nestedKeySym, | ||
@@ -53,2 +54,3 @@ mixinSym, | ||
messageKey: 'msg', | ||
errorKey: 'err', | ||
nestedKey: null, | ||
@@ -93,2 +95,3 @@ enabled: true, | ||
messageKey, | ||
errorKey, | ||
nestedKey, | ||
@@ -168,2 +171,3 @@ base, | ||
[messageKeySym]: messageKey, | ||
[errorKeySym]: errorKey, | ||
[nestedKeySym]: nestedKey, | ||
@@ -170,0 +174,0 @@ // protect against injection |
@@ -437,2 +437,37 @@ 'use strict' | ||
test('dedupe when logs have different levels', function (t) { | ||
let messageCount = 0 | ||
const stream1 = writeStream(function (data, enc, cb) { | ||
messageCount += 1 | ||
cb() | ||
}) | ||
const stream2 = writeStream(function (data, enc, cb) { | ||
messageCount += 2 | ||
cb() | ||
}) | ||
const streams = [ | ||
{ | ||
stream: stream1, | ||
level: 'info' | ||
}, | ||
{ | ||
stream: stream2, | ||
level: 'error' | ||
} | ||
] | ||
const log = pino({ | ||
level: 'trace' | ||
}, multistream(streams, { dedupe: true })) | ||
log.info('info stream') | ||
log.warn('warn stream') | ||
log.error('error streams') | ||
log.fatal('fatal streams') | ||
t.equal(messageCount, 6) | ||
t.end() | ||
}) | ||
test('dedupe when some streams has the same level', function (t) { | ||
@@ -439,0 +474,0 @@ let messageCount = 0 |
@@ -398,8 +398,5 @@ 'use strict' | ||
child.stdout.pipe(writer((s, enc, cb) => { | ||
actual += s | ||
cb() | ||
})) | ||
await once(child, 'close') | ||
await immediate() | ||
for await (const chunk of child.stdout) { | ||
actual += chunk | ||
} | ||
not(strip(actual).match(/Hello/), null) | ||
@@ -406,0 +403,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
464686
146
11223