-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: automatic error formatting in json layout #224
Comments
Hey @Romakita , did you see this issue? 😃 Just noticed that you are not automatically assigned here |
Hello @EinfachHans I haven't found this issue. 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: Reading this article explain how it's possible to serialize error: https://zirkelc.dev/posts/stringify-and-parse-errors-in-javascript. 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 ^^ |
Hey @Romakita, thanks for the explanation! Yeah already thought it is going to be a larger thing 😩 For know i will write a custom logic in my app the works for me 👍🏼 |
You can monkey patch the Exception.prototype.toJSON until we haven’t a good solution ;) |
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: