Hi all, I have run into the following problem with request logger:
I have a RequestCycleListener which populates MDC (logging mapped diagnostic context) with some custom properties such as the sessionId, the userId, and some other stuff. The listener populates the MDC in onBeginRequest and clears the MDC in onEndRequest. What happens is that log entries written by the RequestLogger have empty values for these MDC properties. By digging around I discovered that RequestLogger.log is called in RequestCycle onInternalDetach() which happens after onEndRequest(). So the MDC has been cleared before RequestLogger.log() is called. I think that my approach which uses a RequestCycleListener to populate and clear the MDC is valid and that the RequestLogger should be amended to do the logging before the MDC is cleared (at the latest before RequestCycleListener.onDetach()). Note that even if the MDC is cleared in RequestCycleListener.onDetach() this still happens before RequestLogger.log() is called. Is there something invalid with my approach? I now have a workaround with a custom RequestLogger which clears the MDC in log but this is ugly (if you remove the logger you get a leaking MDC). Any other ideas for workarounds? Thanks Marios