I work with the Vaadin framework and it does not support event capture well, and I cannot know when the session or user interface is activated, so I cannot put their identifiers in the MDC.
Normally I would:
public void onSessionBegin(){ MDC.put("session", VaadinSession.getCurrent().toString());
But I do not have such events, so I would like to:
// in the servlet init or wherever MDC.put("session", new Object(){ public String toString() { VaadinSession.getCurrent().toString() }; }); //<-- This is mutable and will be evaluated each time
Thus, no matter how long the session changes, in the log I will get the current one.
Is it possible? How to replace a logical MDC implementation with a regular one? Should I edit the sources of slf4j and logback?
source share