logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ken Cline" <ken.cl...@ams.com>
Subject RE: MDC in J2EE environment
Date Fri, 04 Apr 2003 00:54:26 GMT

At 04/03/2003 11:09 AM,  Ceki Gülcü wrote:
>
> At 09:58 AM 4/3/2003 -0600, Ebersole, Steven wrote:
> > Actually just another thought occurred to me.  The MDC value is now a
> > ContextCounter instance instead of the actual value I put there.  The
> > default rendering is simply to call the Object's toString() correct?
So it
> > would seem that I would also need to add a renderer or override
toString in
> > ContextCounter to call its context.toString()?
>
> You are right.
>
> public class ContextCounter {
>    int count = 0;
>    Object context;
>
>    public ContextCounter(Object c) { context = c; }
>
>    public void setContext(Object c) { context = c; }
>    public Object getContext() { return context; }
>
>    public boolean isCountZero() { return (count == 0); }
>    public void incCount() { count++; }
>    public void decCount() { count--; }
>
>    // We override toString so that Layouts print the correct information
>    public String toString() { return context.toString(); }
> }

Would it be preferable to use the RendererMap in the toString()
method? That is:
    public class ContextCounter {
       [...]
      public boolean isCountZero() { return (count < 1); }
       [...]
      public String toString() {
        try {
          return getRendererMap().findAndRender( context );
        } catch ( Exception e ) {
          return String.valueOf( context );
        }
      }
    }

Ken.




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Mime
View raw message