NOAA-OWP / wres

Code and scripts for the Water Resources Evaluation Service
Other
2 stars 1 forks source link

As a developer, I want the process id to be logged consistently in all thread contexts #304

Open james-d-brown opened 2 months ago

james-d-brown commented 2 months ago

Given that the process identifier is requested in the logback.xml When I inspect the logging in a given context Then the process identifier should appear on all log lines So that I can distinguish/filter logging associated with a specific application instance (when there are two or more executing)

james-d-brown commented 2 months ago

Currently, log messages executed within threads owned by a ThreadPoolExecutor do not see and log the process identifier, which we share using MDC. Unfortunately, MDC is a very hacky solution and requires a special approach to ThreadPoolExecutor. A better, in-built approach would be ideal. Absent that (and I think there is an absence of that), further hacks may mitigate, like this:

https://medium.com/asyncparadigm/logging-in-a-multithreaded-environment-and-with-completablefuture-construct-using-mdc-1c34c691cef0

Very ugly, though.