Open mrdulin opened 3 years ago
Setting handleExceptions: true
in the transport's options helps, but the error stack is lost. It's mentioned that exceptions are broken in Winston 3: https://github.com/winstonjs/winston/blob/master/examples/exception.js. This issue only happens when the error is provided directly as an argument. When the value of message
is an error then the error is provided to transports' formatters.
I open a MR about this subject to handle format type at transporter level
Any news on this?
The winston-transport module "clones" the info object being formatted:
This leads to only copying enumerable properties, which on Error
objects not even message
is. So the object itself is pretty much blank at that point (at the very least devoid of any Error
properties).
Since the error formatter is expecting an Error
(or at least an error object inside a message property) it does nothing.
An alternative that could work as it is right now:
logToConsole.error({
message: err
});
Which I guess you can monkey patch on the class instance.
const logError = logToConsole.error.bind(logToConsole);
logToConsole.error = (message) => logError({ message });
I'll just point out that the log formatter (that is, the one that's on the logger itself) does not receive a copy of an object but the object itself.
In my use case, I found that setting errors: true
globally interferes with exception logging in a separate file. It turns out that if the option is enabled, undefined gets logged if logging in a separate file.
https://github.com/winstonjs/winston/issues/2195
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v12.16.1What is the problem?
When I use
format.errors({stack: true})
on logger configuration level, it works as expected. The logger parses JavaScriptError
object and prints correctly.Output:
I think the
format.errors({ stack: true })
can be used on transport level too. But it doesn't.Output:
What do you expect to happen instead?
I think the configuration of the logger level is a global configuration, and the configuration of the transport level is the configuration for each transport, and has the highest priority, covering the global configuration.
They are should have the same output.