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 Mike Brodhead <mk...@black-ice.org> on 2001/12/19 19:52:02 UTC

Re: Thread safety


> I am currently seeing garbled log entries in Log4j when two threads
> are logging simultaneously.

Looking through the source, it turns out that PatternLayout is not
thread safe.  PatternLayout uses a StringBuffer instance variable
as scratch space when laying out a log entry.

The solution is to use a separate PatternLayout instance for each
Appender, even if they all use the same conversion string.

Suggestion:  Since Log4j is billed as thread safe, it might be
a good idea to document cases like this in the javadoc.

--mkb


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>