quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.81k stars 2.69k forks source link

Clean way of sanitizing exceptions log messages #44153

Open rasmuscc opened 2 weeks ago

rasmuscc commented 2 weeks ago

Description

Currently, it's possible to filter log messages in Quarkus by creating a @LoggingFilter, which provides access to java.util.logging.LogRecord. However, I think there’s a limitation when it comes to sanitizing logged exception messages.

The issue is that while I can access the LogRecord's cause, it’s immutable. To sanitize exception messages, I think I'd need to iterate through the cause chain and create a new exception with an updated message for each cause which is cumbersome.

It would be beneficial to have a filter that directly applies to the final output written to the console. This would allow for easier sanitization of exception messages without needing to recreate the cause chain.

Implementation ideas

No response

quarkus-bot[bot] commented 2 weeks ago

/cc @dmlloyd (logging)

dmlloyd commented 2 weeks ago

We could approach this in two different ways:

rasmuscc commented 2 weeks ago

Which solution offers the best performance? Also, isn't it in theory possible for cycles to exist in the cause chain?

dmlloyd commented 2 weeks ago

I think the latter is likely to have the lowest run time overhead. And yes, cycles may exist in the causes chains but that isn't insurmountable.

rasmuscc commented 1 week ago

Thank you for the answer! I think the latter sounds like the "nicest" solution.