[slf4j-user] Marker for object identification?
Newcomb, Michael-P57487
Michael.Newcomb at gdc4s.com
Wed Feb 7 21:50:10 CET 2007
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
More information about the slf4j-user
mailing list