Skip to content

fix: preserve prototype chain in child logger info objects#2609

Open
mixelburg wants to merge 1 commit into
winstonjs:masterfrom
mixelburg:fix/child-logger-prototype-chain
Open

fix: preserve prototype chain in child logger info objects#2609
mixelburg wants to merge 1 commit into
winstonjs:masterfrom
mixelburg:fix/child-logger-prototype-chain

Conversation

@mixelburg
Copy link
Copy Markdown

Fixes #2577

The child() method uses Object.assign({}, defaultRequestMetadata, info) to merge metadata, which only copies enumerable own properties. When info is an Error subclass or any custom class instance, its prototype chain is lost — instanceof checks and custom methods no longer work.

The existing code already handles Error explicitly by copying stack, message, and cause, but this doesn't cover custom subclasses or non-Error prototypes. Using Object.create(Object.getPrototypeOf(info)) as the target for Object.assign preserves the prototype chain for all objects, not just Error instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Info prototype destroyed by child logger

1 participant