logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Log4j2's SimpleLogger Implementation Issue for var args method's
Date Tue, 02 Sep 2014 14:35:24 GMT
Yogesh,

Thank you for you message.

We can only take code submissions via unified diff files attached to JIRA.
I think we might also be able to (legally) accept Git pull requests but I
am not 100% sure on that one.

When providing a patch it would be most helpful to do so against the Git
master branch.

In any case, please create JIRA issue.

Thank you,
Gary


On Tue, Sep 2, 2014 at 10:24 AM, Yogesh Rao <yogu13@gmail.com> wrote:

> Hi,
>
> There seems to be an issue with SimpleLogger implementation provided by
> log4j2. The issue seems to be in the new improved API supporting
> placeholders and var args when called with an Object Array of size 0.
>
> for e.g logger.error("Hello World {} in {} " , new Object[0]);
>
> A statement above results in an error as shown below
>
> ERROR StatusLogger Unable to locate a logging implementation, using
> SimpleLogger
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
>        at
>
> org.apache.logging.log4j.simple.SimpleLogger.logMessage(SimpleLogger.java:157)
>        at
>
> org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1347)
>        at
>
> org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1312)
>        at
> org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:539)
>        at TestError.main(TestError.java:21)
>
>
>
> I managed to look at the code as well and it looks like a condition to
> check of the var arg param array size is missing in SimpleLogger
>
>  155 final Object[] params = msg.getParameters();
>  156         Throwable t;
>  157         if (throwable == null && params != null &&
> params[params.length - 1] instanceof Throwable) {
>  158             t = (Throwable) params[params.length - 1];
>  159         } else {
>  160             t = throwable;
>  161         }
>  162         if (t != null) {
>  163             sb.append(SPACE);
>  164             final ByteArrayOutputStream baos = new
> ByteArrayOutputStream();
>  165             t.printStackTrace(new PrintStream(baos));
>  166             sb.append(baos.toString());
>  167         }
>  168         stream.println(sb.toString());
>
>
> I can raise a JIRA issue and provide a fix with failing unit testcase. Let
> me know if i can proceed ahead on this.
>
> Details of the environment are :-
> Version used
>
>  1. JDK - Oracle JDK version 1.7
>  2. Log4j2 API - 2.0.1
>
>
> To reproduce following java class can be used :
>
> TestError.java
> ------------------------
>
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
>
>
>
> public class TestError {
>
> private static final Logger logger = LogManager.getLogger("TestError");
> /**
>  * @param args
>  */
> public static void main(String[] args) {
> Object[] arr = null;
> logger.error("Hello World {} in {} " , new Object[0]);
>
> }
>
> }
>
> Jars in Classpath
> --------------------------
> Log4j2 API - 2.0.1
>
>
> Regards,
> -Yogesh
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message