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
This information is explicit added by the PlatformLogMiddleware of @tsed. Maybe it would make sense something similar to the logger itself? Maybe here? Where when an error is detected within the data it could be handled separately.
Or is this not a good solution for some reasons? Then i would have to implement something in my application.
The text was updated successfully, but these errors were encountered:
The problem is around the error object itself (detecting will be a huge cost, because we need to introspect object and nested object), JSON.stringify isn't able to serialize the error instance because Error.prototype haven't a toJSON method. We can see that here:
The problem is how to support that correctly for all possible Error type (and custom Error) without exposing critical information of our application (Error.stack ??). This is actually why I haven't fixed this problem on logger level.
Note: @tsed/logger code base was originally based on log4js, and the team haven't fixed that ^^
Informations
Description
I'm currently in process of understanding the logger and how it works. I have problems with a usefull error formatting:
For production i enabled the json layout. See the following comparison, between what i log and what the output is:
this.logger.error('some error', exception)
{"startTime":"2023-11-14T14:30:30.024Z","categoryName":"ExceptionsFilter","level":"ERROR","data":["some error"]}
this.logger.error(exception)
{"startTime":"2023-11-14T14:31:21.042Z","categoryName":"ExceptionsFilter","level":"ERROR","data":[]}
this.logger.error({ message: 'some error', exception })
{"startTime":"2023-11-14T14:32:23.111Z","categoryName":"ExceptionsFilter","level":"ERROR","message":"some error","exception":{},"data":[]}
In all of this variants the information about the exception (
new Error('test')
in my case) is missing.What would i expect? Good question. When a error ocours the default context logger logs something like this:
{"startTime":"2023-11-14T14:32:23.113Z","categoryName":"Default","level":"ERROR","method":"GET","url":"/healthz","route":"/healthz","headers":{...},"body":{},"query":{},"params":{},"reqId":"f3dc11e567e24389b9847d7321643533","time":"2023-11-14T14:32:23.113Z","duration":9,"event":"request.end","status":500,"status_code":"500","state":"KO","error_name":"Error","error_message":"test","error_stack":"...","data":[]}
This information is explicit added by the PlatformLogMiddleware of
@tsed
. Maybe it would make sense something similar to the logger itself? Maybe here? Where when an error is detected within the data it could be handled separately.Or is this not a good solution for some reasons? Then i would have to implement something in my application.
The text was updated successfully, but these errors were encountered: