logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: Logger and threads
Date Fri, 19 Sep 2003 08:29:56 GMT

Ciao Matteo,

Logger is thread safe. See also below.

At 10:06 AM 9/19/2003 +0200, Matteo Sotil Bertanzetti wrote:
>My first question: Is Logger thread safe?.
>
>I mean, if multiple threads use one same Logger instance, is there some 
>synchronization problem?, is necessary to synchronize it with some code 
>like: synchronized(logger){logger.debug("");} ?.
>If it is necessary as I guess, I think is better to use an internal 
>function to avoid repeating 'synchronized... if(logger.isDebugEnabled()) 
>....' every time you want to log; for example:
>
>private void debug(String sMessage)
>{
>     synchronized(logger)
>     {
>         if(logger.isDebugEnabled())
>         {
>             logger.debug(sMessage);
>         }
>     }
>}
>
>Am I right?. But in this case, logger.isDebugEnabled() is useless, because 
>cost of constructing string is already done; isn't it?.

Correct. But logger is thread safe.

>One solution I see to this problem is using just4log 
>(http://just4log.sourceforge.net/), as Milind Rao pointed on last message.

>My second question: if Logger is not thread safe, what is the better 
>choice to make it safe?.

but Logger is thread safe. :-)

>Thank you and sorry for my English...

I hope this alleviates your concerns.

>Matteo

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp

      import org.apache.Facetime;
      ApacheCon US 2003, 18-21 November http://apachecon.com/



---------------------------------------------------------------------
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