[slf4j-user] Marker for object identification?
Ceki Gülcü
listid at qos.ch
Thu Feb 8 20:40:21 CET 2007
Response below.
At 10:08 PM 2/7/2007, Newcomb, Michael-P57487 wrote:
>The use case is you have a IoHandler (mina.apache.org) handling
>information for a specific IoSession. Each session is unique but IoHandler
>logs like this:
>
>log.debug("message received: {}", message);
>
>DEBUG [IoHandler] message received: message 1
>DEBUG [IoHandler] message received: message 1
>DEBUG [IoHandler] message received: message 2
>DEBUG [IoHandler] message received: message 1
>DEBUG [IoHandler] message received: message 3
>DEBUG [IoHandler] message received: message 2
>DEBUG [IoHandler] message received: message 2
>DEBUG [IoHandler] message received: message 3
>DEBUG [IoHandler] message received: message 3
>
>Doesn't tell me anything about which session received which message.
>
>I was thinking logging the following:
>
>log.debug(sessionMarker, "message received: {}", message);
>
>With a pattern that took into account the marker would log like:
>
>DEBUG [IoHandler] [192.168.0.1/12345] message received: message 1
>DEBUG [IoHandler] [192.168.0.2/12345] message received: message 1
>DEBUG [IoHandler] [192.168.0.2/12345] message received: message 2
>DEBUG [IoHandler] [192.168.0.3/12345] message received: message 1
>DEBUG [IoHandler] [192.168.0.2/12345] message received: message 3
>DEBUG [IoHandler] [192.168.0.1/12345] message received: message 2
>DEBUG [IoHandler] [192.168.0.3/12345] message received: message 2
>DEBUG [IoHandler] [192.168.0.3/12345] message received: message 3
>DEBUG [IoHandler] [192.168.0.1/12345] message received: message 3
>
>I could also create a new Logger after IoHandler...
>
>Logger log = LoggerFactory.getLogger(getClass() + "." + session);
>
>But that would mess with the default '.' hierarchy if I used a IP address
>as the session key.
>
>I'm asking what would be a good approach to the above problem.
Assuming you can inject the marker information related the session to the
components that need to log, the marker approach should be OK as long as
the number of markers (hence sessions) is limited. Markers cannot be
removed, so they will just sit there until all memory is exhausted.
If on the other hand, you cannot inject the information, MDC is the only
way to go.
Would you care to file a bug report so that Markers become removable?
>Thanks,
>Michael
--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
More information about the slf4j-user
mailing list