VEuPathDB / lib-jaxrs-container-core

Core library for VEuPathDB JaxRS container services
Apache License 2.0
0 stars 0 forks source link

Add request times to container request logging. #11

Open Foxcapades opened 2 years ago

Foxcapades commented 2 years ago

This is a feature we have in WDK to show how much time has elapsed at log time since the beginning of the request. A jersey filter attaches some information to the request's thread context (Map<String,Object>, which is queried as part of the log line pattern's macro substitution. In Log4j 1.x, the substitution value is the Object.toString() value. So we created an object that retained the request's start time, the in its toString(), calculated the time and returned it.

This method does not work in Log4j2, because, to be more efficient, Log4j2 substitutes the thread context macros only once, then caches them. A solution seemed to be to create a new kind of substitution method (there are many, including date/time, thread context, etc.) and refer to it in the pattern. If we do that, we should be able to substitute with whatever we want.

@ryanrdoherty tried to do this a while back, creating this class in FgpUtil (thinking we would use it in WDK, etc. in the future after we move away from the log4j 1.x APIs). It didn't quite work, but since then, we've modified the way log4j plugins are added to the runtime during the build, so it might be worth trying again.

See this package for both the PatternConverter subclass and the class that handles storing off request information. https://github.com/VEuPathDB/FgpUtil/tree/master/Core/src/main/java/org/gusdb/fgputil/logging