diff --git a/CHANGES.md b/CHANGES.md index 47ab1e4..069264e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,12 @@ ## bunyan 0.6.8 (not yet released) -(nothing yet) +- Fix bad bug in `log.child({...}, true);` where the added child fields **would + be added to the parent's fields**. This bug only existed for the "fast child" + path (that second `true` argument). A side-effect of fixing this is that + the "fast child" path is only 5 times as fast as the regular `log.child`, + instead of 10 times faster. + ## bunyan 0.6.7 diff --git a/lib/bunyan.js b/lib/bunyan.js index 97a99bf..a584092 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -239,19 +239,24 @@ function Logger(options, _childOptions, _childSimple) { // Fast path for simple child creation. if (parent && _childSimple) { - // Single to stream close handling that this child owns none of its - // streams. + // `_isSimpleChild` is a signal to stream close handling that this child + // owns none of its streams. this._isSimpleChild = true; this._level = parent._level; this.streams = parent.streams; this.serializers = parent.serializers; this.src = parent.src; - this.fields = parent.fields; + var fields = this.fields = {}; + var parentFieldNames = Object.keys(parent.fields); + for (var i = 0; i < parentFieldNames.length; i++) { + var name = parentFieldNames[i]; + fields[name] = parent.fields[name]; + } var names = Object.keys(options); for (var i = 0; i < names.length; i++) { var name = names[i]; - this.fields[name] = options[name]; + fields[name] = options[name]; } return; }