You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is instead due to child logger doing cloning like
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);
}
}
});
}
I think I'm running into this issue too. In my case I'm not explicitly creating a child logger, but I am throwing an exception and expecting winston's ExceptionHandler to pick it up, and something similar is happening. The errors formatter doesn't do anything because einfo isn't an Error, although einfo.error is, and einfo.message is just a string:
The above debugger screenshot is just what happens when I throw an uncaught exception:
} catch (e) {
throw new Error("Blah blah", { cause: e });
}
with winston.format.errors({ stack: true, cause: true }) in my logger format and handleExceptions: true in my transport. I'm surprised more people haven't run into this.
馃攷 Search Terms
Child logger
The problem
Logger defined like this:
Error formatter uses
info instanceof Error
check to apply it's logic:But the child logger here changes the type:
so the error formatter is not applied at all.
I can workaround this by putting the error into the
message
property, but not sure that's how it should be done:due to this check:
What version of Winston presents the issue?
3.11.0
What version of Node are you using?
v16.20.0
If this worked in a previous version of Winston, which was it?
No response
Minimum Working Example
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: