Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const {
asChindings,
asJson,
buildFormatters,
stringify
stringify,
noop
} = require('./tools')
const {
version
Expand Down Expand Up @@ -86,11 +87,32 @@ function child (bindings, options) {
if (!bindings) {
throw Error('missing bindings for child Pino')
}
options = options || {} // default options to empty object
const serializers = this[serializersSym]
const formatters = this[formattersSym]
const instance = Object.create(this)

// If an `options` object was not supplied, we can improve
// the performance of child creation by skipping
// the checks for set options and simply return
// a baseline instance.
if (options == null) {
Comment thread
mcollina marked this conversation as resolved.
if (instance[formattersSym].bindings !== resetChildingsFormatter) {
Comment thread
ronag marked this conversation as resolved.
instance[formattersSym] = buildFormatters(
formatters.level,
resetChildingsFormatter,
formatters.log
)
}

instance[chindingsSym] = asChindings(instance, bindings)

if (this.onChild !== noop) {
this.onChild(instance)
}
Comment thread
mcollina marked this conversation as resolved.

return instance
}

if (options.hasOwnProperty('serializers') === true) {
instance[serializersSym] = Object.create(null)

Expand Down Expand Up @@ -223,8 +245,6 @@ function write (_obj, msg, num) {
stream.write(streamWriteHook ? streamWriteHook(s) : s)
}

function noop () {}

function flush (cb) {
if (cb != null && typeof cb !== 'function') {
throw Error('callback must be a function')
Expand Down
4 changes: 2 additions & 2 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ function asChindings (instance, bindings) {

for (const key in bindings) {
value = bindings[key]
const valid = key !== 'level' &&
const valid = (key.length < 5 || (key !== 'level' &&
key !== 'serializers' &&
key !== 'formatters' &&
key !== 'customLevels' &&
key !== 'customLevels')) &&
Comment thread
mcollina marked this conversation as resolved.
bindings.hasOwnProperty(key) &&
value !== undefined
if (valid === true) {
Expand Down