You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ana Paula Brandão Lopes <ap...@yahoo.com.br> on 2005/02/19 18:23:43 UTC

is log4j thread-safe?

Hello,
I was learning about using NDC to diferentiate logging coming from  
diferente clients on web-apps, by reading this:   
http://www.onjava.com/pub/a/onjava/2002/08/07/log4j.html?page=3
The docs say every thread has its own NDC, but when the logging is sent,  
the appender is the same for all threads. I was looking for "synchronized"  
on logging methods (like Logger.debug(), or Logger.info()) or even on  
Appenders methods, but couldn´t find it.
This made me wonder. Is logging on log4j thread-safe?
Thanks in advance,
Ana

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/



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


Re: is log4j thread-safe?

Posted by Curt Arnold <ca...@apache.org>.
On Feb 19, 2005, at 11:23 AM, Ana Paula Brandão Lopes wrote:

> Hello,
> I was learning about using NDC to diferentiate logging coming from 
> diferente clients on web-apps, by reading this:  
> http://www.onjava.com/pub/a/onjava/2002/08/07/log4j.html?page=3
> The docs say every thread has its own NDC, but when the logging is 
> sent, the appender is the same for all threads. I was looking for 
> "synchronized" on logging methods (like Logger.debug(), or 
> Logger.info()) or even on Appenders methods, but couldn´t find it.
> This made me wonder. Is logging on log4j thread-safe?
> Thanks in advance,
> Ana
>


See http://logging.apache.org/log4j/docs/faq.html#1.7

It would be undesirable to have synchronized on the logging methods 
since that would block other threads from logging for the time it takes 
to complete the entire logging operation.  If you search the log4j code 
base, you will many synchronization blocks that prevent conflicting 
access to the same shared resources, however they are designed to allow 
as much non-conflicting access as possible and to minimize the duration 
other threads may be blocked.

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