logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Watts <ti...@earthlink.net>
Subject Re: Adding a custom variable to Log4j logging calls
Date Thu, 20 Mar 2008 14:59:13 GMT

I suppose java.text.MessageFormat would do. For example:

log.debug(MessageFormat.format("Something happened; the context is [{1}]", 
myContextObj));

Although frankly, the simpler approach is something like this:

if (log.isDebugEnabled()) {
   log.debug("Something happened; the context is [" +myContextObj +"]");
}

The isDebugEnabled() call is an optimization technique. It allows the program 
to skip the string construction if the log isn't going to write debug 
messages anyway.


On Thursday 20 March 2008 9:07 am, dertown wrote:
> that would work how would i format a message?
>
> James A. N. Stauffer wrote:
> > Is there a reason why appending the strings doesn't work?  I think you
> > can use format messages.
> >
> > On Wed, Mar 19, 2008 at 9:57 AM, dertown <derek.townsend@perspecsys.com>
> >
> > wrote:
> >>  Hi Everyone
> >>
> >>  I am newbi with log4j ,  i was wondering if there is any example code
> >> on how
> >>  to add a custom variable to a log4j logging call.
> >>
> >>  the default is log.log("DEBUG","log message");
> >>
> >>  I would like to add another custom variable here to allow for some
> >>  additional information.
> >>
> >>  so the new log call will be log.log("DEBUG","log message","more info");
> >>
> >>  Thanks
> >>  Derek
> >>  --
> >>  View this message in context:
> >> http://www.nabble.com/Adding-a-custom-variable-to-Log4j-logging-calls-tp
> >>16145549p16145549.html Sent from the Log4j - Users mailing list archive
> >> at Nabble.com.
> >>
> >>
> >>  ---------------------------------------------------------------------
> >>  To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>  For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> > --
> > James A. N. Stauffer http://www.geocities.com/stauffer_james/
> > Are you good? Take the test at http://www.livingwaters.com/good/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org

-- 
"Absolute security comes with chains."

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


Mime
View raw message