-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Lines 45 to 71 in 71ee92a
| child(defaultRequestMetadata) { | |
| const logger = this; | |
| return Object.create(logger, { | |
| write: { | |
| value: function (info) { | |
| const infoClone = Object.assign( | |
| {}, | |
| defaultRequestMetadata, | |
| info | |
| ); | |
| // Object.assign doesn't copy inherited Error | |
| // properties so we have to do that explicitly | |
| // | |
| // Remark (indexzero): we should remove this | |
| // since the errors format will handle this case. | |
| // | |
| if (info instanceof Error) { | |
| infoClone.stack = info.stack; | |
| infoClone.message = info.message; | |
| } | |
| logger.write(infoClone); | |
| } | |
| } | |
| }); | |
| } |
Hello, based on the code here, the prototype chain is lost for any info object being passed in.
If I want to for example use Error objects in the log method and based on their prototype (using instanceof) apply some mapping, creating a child logger would remove this prototype because the Object.assign just copies it's enumerable properties.
Would it be possible to add this line inside the if, or perhaps some more elegant solution?
infoClone.__proto__ = info.__proto__;
The reason why I believe this would be fine is that there is no guarantee of not modifying the original object in case you are not using the child method anyway.
Metadata
Metadata
Assignees
Labels
No labels