[slf4j-user] Marker for object identification?
Newcomb, Michael-P57487
Michael.Newcomb at gdc4s.com
Wed Feb 7 22:08:06 CET 2007
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.
Thanks,
Michael
-----Original Message-----
From: user-bounces at slf4j.org [mailto:user-bounces at slf4j.org] On Behalf Of Ceki Gülcü
Sent: Wednesday, February 07, 2007 3:57 PM
To: User list for the slf4j project
Subject: Re: [slf4j-user] Marker for object identification?
What is the use case? How do you intend to take advantage of the marker information?
At 09:50 PM 2/7/2007, you wrote:
>This example was thread specific, but my specific use involves multiple
>sessions (mina.apache.org) serviced by a thread pool. So, a context
>needs to be associated with the session and not the thread servicing it.
>
>
>-----Original Message-----
>From: user-bounces at slf4j.org [mailto:user-bounces at slf4j.org] On Behalf
>Of Ceki Gülcü
>Sent: Wednesday, February 07, 2007 3:41 PM
>To: User list for the slf4j project; User list for the slf4j project
>Subject: Re: [slf4j-user] Marker for object identification?
>
>
>If you just want to differentiate between multiple threads, you can use
>set an MDC [1]. When your runnable object gets garbage-collected, so
>will the MDC. The Marker solution could also work, except that Markers
>can only be created, not deleted. (Markers do not need to exist in a
>config file to be referenced in code. You can create a marker at any
>time.)
>
>So for in the case of your example as presented in your message, I'd go
>with MDC.
>
>[1] http://logback.qos.ch/manual/mdc.html
>
>At 09:25 PM 2/7/2007, Newcomb, Michael-P57487 wrote:
> >public class Foo
> > implements Runnable
> >{
> > protected final String name;
> >
> > protected final Marker marker;
> > protected final Logger log = LoggerFactory.getLogger(getClass());
> >
> > public Foo(String name)
> > {
> > this.name = name;
> >
> > marker = MarkerFactory.getMarker(name);
> > }
> >
> > public void run()
> > {
> > while (true)
> > {
> > ...
> >
> > log.debug(marker, "some stuff");
> >
> > ...
> > }
> > }
> >}
> >
> >new Thread(new Foo("A")).start();
> >new Thread(new Foo("B")).start();
> >
> >
> >So you could see the logs for each Foo ('A' and 'B')...
> >
> >Also, can Markers be created on the fly by using
> >MarkerFactory.getMarker()? Or does that Marker have to exist in a
> >config file somewhere... (e.g. what does LogBack do?)
> >
> >Thanks,
> >Michael
> >
> >
> >-----Original Message-----
> >From: user-bounces at slf4j.org [mailto:user-bounces at slf4j.org] On
> >Behalf Of Ceki Gülcü
> >Sent: Wednesday, February 07, 2007 3:14 PM
> >To: user at slf4j.org
> >Subject: Re: [slf4j-user] Marker for object identification?
> >
> >
> >Hi Michael,
> >
> >I don't fully understand your question. However, you can use a marker
> >to color a log request so that it triggers some particular treatment.
> >Does this help?
> >
> >At 09:10 PM 2/7/2007, Newcomb, Michael-P57487 wrote:
> >
> > >Can/Should markers be used to identify specific objects? The only
> > >example I see is for use with the 'TRACE' marker, but was wondering
> > >if markers could/should be used object identification as well.
> > >
> > >Thanks,
> > >Michael
> > >_______________________________________________
> > >user mailing list
> > >user at slf4j.org
> > >http://www.slf4j.org/mailman/listinfo/user
> >
> >--
> >Ceki Gülcü
> >Logback: The reliable, generic, fast and flexible logging framework
> >for
> Java.
> >http://logback.qos.ch
> >
> >_______________________________________________
> >user mailing list
> >user at slf4j.org
> >http://www.slf4j.org/mailman/listinfo/user
> >_______________________________________________
> >user mailing list
> >user at slf4j.org
> >http://www.slf4j.org/mailman/listinfo/user
>
>--
>Ceki Gülcü
>Logback: The reliable, generic, fast and flexible logging framework for Java.
>http://logback.qos.ch
>
>_______________________________________________
>user mailing list
>user at slf4j.org
>http://www.slf4j.org/mailman/listinfo/user
>_______________________________________________
>user mailing list
>user at slf4j.org
>http://www.slf4j.org/mailman/listinfo/user
--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
_______________________________________________
user mailing list
user at slf4j.org
http://www.slf4j.org/mailman/listinfo/user
More information about the slf4j-user
mailing list