Skip to content

Commit

Permalink
Merge 70459c6 into 4bcc170
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Aug 14, 2018
2 parents 4bcc170 + 70459c6 commit 1eb5064
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/api.md
Expand Up @@ -15,6 +15,7 @@
* [logger.level](#level)
* [logger.isLevelEnabled()](#islevelenabled)
* [logger.levels](#levels)
* [logger\[Symbol.for('pino.serializers')\]](#serializers)
* [Event: 'level-change'](#level-change)
* [logger.version](#version)
* [logger.LOG_VERSION](#log_version)
Expand Down Expand Up @@ -543,6 +544,13 @@ $ node -p "require('pino')().levels"

* See [`logger.level`](#level)

<a id="serializers"></a>
### logger\[Symbol.for('pino.serializers')\]

Returns the serializers for the logger instance, as seen by the logger
itself. Child loggers might reuse the same instance of their parent, if
there are no changes.

<a id="level-change"></a>
### Event: 'level-change'

Expand Down
4 changes: 3 additions & 1 deletion lib/symbols.js
Expand Up @@ -10,7 +10,6 @@ const parsedChindingsSym = Symbol('pino.parsedChindings')

const asJsonSym = Symbol('pino.asJson')
const writeSym = Symbol('pino.write')
const serializersSym = Symbol('pino.serializers')
const redactFmtSym = Symbol('pino.redactFmt')

const timeSym = Symbol('pino.time')
Expand All @@ -21,6 +20,9 @@ const endSym = Symbol('pino.end')
const formatOptsSym = Symbol('pino.formatOpts')
const messageKeyStringSym = Symbol('pino.messageKeyString')

// public symbols, no need to use the same pino
// version for these
const serializersSym = Symbol.for('pino.serializers')
const wildcardGsym = Symbol.for('pino.*')
const needsMetadataGsym = Symbol.for('pino.metadata')

Expand Down
23 changes: 23 additions & 0 deletions test/serializers.test.js
Expand Up @@ -91,6 +91,29 @@ test('child does not overwrite parent serializers', async ({is}) => {
is((await o2).test, 'child')
})

test('Symbol.for(\'pino.serializers\')', async ({is, isNot}) => {
const stream = sink()
const parent = pino({ serializers: parentSerializers }, stream)
const child = parent.child({a: 'property'})

is(parent[Symbol.for('pino.serializers')], parentSerializers)
is(child[Symbol.for('pino.serializers')], parentSerializers)

const child2 = parent.child({
serializers: {
a
}
})

function a () {
return 'hello'
}

isNot(child2[Symbol.for('pino.serializers')], parentSerializers)
is(child2[Symbol.for('pino.serializers')].a, a)
is(child2[Symbol.for('pino.serializers')].test, parentSerializers.test)
})

test('children inherit parent serializers', async ({is}) => {
const stream = sink()
const parent = pino({ serializers: parentSerializers }, stream)
Expand Down

0 comments on commit 1eb5064

Please sign in to comment.