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 "Farrish, Eric T, (Thor), CTR, AUTEC" <Er...@autec.navy.mil> on 2007/06/27 15:17:37 UTC

Difference in behavior between 1.3A8 and 1.2.14 (StringIndexOutOfBounds exception)

Hi all.

I recently moved from 1.2.14 to 1.3-alpha8 and began experiencing
StringIndexOutOfBounds
exceptions when logging.

I tracked the problem down to having multiple threads logging to two
appenders, and the
Two appenders sharing a common PatternLayout object.  My code
initializes the
appenders thus:

...
...
PatternLayout pLayout = new PatternLayout("%d %-5p - %m%n");

FileAppender fAppender = new FileAppender(pLayout, "C:\\test.log");
ConsoleAppender cAppender = new ConsoleAppender(pLayout);

logger.addAppender(fAppender);
logger.addAppender(cAppender);
...
...

I solved the problem by creating a unique PatternLayout object for each
Appender.

I see there's a quite a bit of difference between the 1.2.X and 1.3.X
codebases.  I think the
problem isn't manifest in 1.2.X because PatternConverter.format() is
calling StringBuffer.append()
on the formatting string, while in 1.3.X FormattingInfo.format() is
using StringBuffer.insert()
(although it could be (probably is) just a timing thing).

My question is:  Will the bahavior of 1.3.X change in the future such
that I can use only
one PatternLayout for multiple appenders, or should I change my legacy
code to be more
defensive and allocate a PatternLayout for each Appender.

Thanks in advance.

Re: Difference in behavior between 1.3A8 and 1.2.14 (StringIndexOutOfBounds exception)

Posted by Curt Arnold <ca...@apache.org>.
On Jun 27, 2007, at 8:17 AM, Farrish, Eric T, (Thor), CTR, AUTEC wrote:

> Hi all.
>
> I recently moved from 1.2.14 to 1.3-alpha8 and began experiencing  
> StringIndexOutOfBounds
> exceptions when logging.
>
> I tracked the problem down to having multiple threads logging to  
> two appenders, and the
> Two appenders sharing a common PatternLayout object.  My code  
> initializes the
> appenders thus:
>
> …
> …
> PatternLayout pLayout = new PatternLayout("%d %-5p - %m%n");
>
> FileAppender fAppender = new FileAppender(pLayout, "C:\\test.log");
> ConsoleAppender cAppender = new ConsoleAppender(pLayout);
>
> logger.addAppender(fAppender);
> logger.addAppender(cAppender);
> …
> …
>
> I solved the problem by creating a unique PatternLayout object for  
> each Appender.
>
> I see there's a quite a bit of difference between the 1.2.X and  
> 1.3.X codebases.  I think the
> problem isn't manifest in 1.2.X because PatternConverter.format()  
> is calling StringBuffer.append()
> on the formatting string, while in 1.3.X FormattingInfo.format() is  
> using StringBuffer.insert()
> (although it could be (probably is) just a timing thing).
>
> My question is:  Will the bahavior of 1.3.X change in the future  
> such that I can use only
> one PatternLayout for multiple appenders, or should I change my  
> legacy code to be more
> defensive and allocate a PatternLayout for each Appender.
>
> Thanks in advance.
>
>

The log4j 1.3 code base is in the process of being abandoned as there  
was no realistic hope that continued development would result in a   
version that could be sufficiently compatible with log4j 1.2 to be  
released.  Several useful features (new rolling file appender,  
enhanced pattern layout, etc) from log4j 1.3 have been backported as  
"companions" to log4j 1.2.  Unfortunately, none of that currently  
shows up on the public web site at the moment.

log4j 2.0 development is in an early experimental phase but thread- 
safety is a huge design criteria, so it is unlikely that the log4j  
1.3 behavior would be replicated.

I would recommend staying with log4j 1.2 and let the list know what  
features were motivating you to migrate to log4j 1.3 and we can let  
you know their status for use with log4j 1.2.