Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Matt Sicker
Camel accepts PRs. I think we should be able to do it. ICLAs still apply,
though.


On 2 September 2014 12:12, Ralph Goers  wrote:

> That sounds reasonable.
>
> Ralph
>
>
> On Sep 2, 2014, at 9:41 AM, Yogesh Rao  wrote:
>
> > Hi Ralph,
> >
> > IMO new Object[0] as a param value is valid and should behave similar to
> a
> > call to the method without param i.e. logger.error("Hello World {} in {}
> ");
> >
> > In the above context adding a conditional check params.length > 0 with
> then
> > the "if" @ line 157 wouldn't end up throwing the error and print the
> given
> > message
> >
> > Regards,
> > -Yogesh
> >
> >
> > On Tue, Sep 2, 2014 at 9:45 PM, Ralph Goers 
> > wrote:
> >
> >> What will you do instead of throwing an ArrayIndexOutOfBoundsException?
> >> This is obviously a user error.  It would be misleading (but maybe
> >> acceptable) to substitute “null” for the placeholders, but just
> throwing a
> >> different exception probably isn’t worth the trouble.
> >>
> >> Ralph
> >>
> >> On Sep 2, 2014, at 7:24 AM, Yogesh Rao  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
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> >> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >>
> >>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
Matt Sicker 


Re: Log4j2 with SL4J Adapter

2014-09-02 Thread Matt Sicker
If you prefer using GitHub, you can file a pull request instead of a patch
file. I still want to test out the functionality, but it should work just
fine.


On 2 September 2014 09:29, Yogesh Rao  wrote:

> Hi,
>
> Just an update on this... i had little time last week to work on this
> issue. I am looking into this now and checking if a sandbox can be created
> for execution of the test cases using class loaders.
>
> Thank you!
>
> Regards,
> -Yogesh
>
>
> On Mon, Aug 25, 2014 at 10:48 AM, Yogesh Rao  wrote:
>
> > Sure Remko! Will try for it.
> >
> > Thank you!
> >
> > Regards,
> > -Yogesh
> >
> > On Monday, August 25, 2014, Remko Popma  wrote:
> >
> >> Great, thank you! I'll have limited PC access the next ten days or so.
> >> If you want to take a stab at providing a patch that includes both a
> JUnit
> >> test and a fix, go for it!
> >>
> >>
> >> On Sun, Aug 24, 2014 at 11:31 PM, Yogesh Rao  wrote:
> >>
> >> > Defect logged under LOG4J2-796
> >> >
> >> > Regards,
> >> > -Yogesh
> >> >
> >> >
> >> > On Sun, Aug 24, 2014 at 2:41 PM, Remko Popma 
> >> > wrote:
> >> >
> >> > > Yogesh,
> >> > >
> >> > > Thanks! Both would be really helpful!
> >> > >
> >> > > Remko
> >> > >
> >> > > Sent from my iPhone
> >> > >
> >> > > > On 2014/08/24, at 9:09, Yogesh Rao  wrote:
> >> > > >
> >> > > > Thanks Remko!
> >> > > >
> >> > > > would you like me to create a JIRA ticket for the same ? I could
> >> also
> >> > try
> >> > > > giving a shot at creating that unit test case for you..
> >> > > >
> >> > > > Regards,
> >> > > > -Yogesh
> >> > > >
> >> > > >
> >> > > >> On Sun, Aug 24, 2014 at 12:35 PM, Remko Popma <
> >> remko.po...@gmail.com>
> >> > > wrote:
> >> > > >>
> >> > > >> This looks like a bug. The output is the FQCN (fully qualified
> >> name of
> >> > > the
> >> > > >> logger).
> >> > > >> This is probably introduced by the changes made for LOG4J2-555.
> >> > > >>
> >> > > >> Our unit tests are not picking this up because they use
> >> > > >> the ch.qos.logback.classic.Logger, which is a LocationAwareLogger
> >> and
> >> > > >> follows a different code path.
> >> > > >> I suspect that Simple Logger is not LocationAware.
> >> > > >>
> >> > > >> I suspect we should change (in SLF4JLogger.logMessage)
> >> > > >> logger.debug(fqcn, getMarker(marker),
> >> > message.getFormattedMessage(),
> >> > > >> message.getParameters(), t);
> >> > > >> to
> >> > > >> logger.debug(getMarker(marker),
> message.getFormattedMessage(),
> >> > > >> message.getParameters(), t);
> >> > > >>
> >> > > >> I can change this but want to make a failing unit test first and
> I
> >> > > haven't
> >> > > >> had time to figure out how to do that yet.
> >> > > >>
> >> > > >>
> >> > > >>
> >> > > >>> On Sun, Aug 24, 2014 at 12:00 PM, Yogesh Rao 
> >> > wrote:
> >> > > >>>
> >> > > >>> Hi Ralph,
> >> > > >>>
> >> > > >>> The issue for me is log4j2 to slf4j adaptor doesnt seem to be
> >> > working.
> >> > > I
> >> > > >>> added the log4j configuration only when the logger wasnt working
> >> > hence
> >> > > i
> >> > > >>> mentioned in brackets that i wasnt sure if its needed or not..
> >> > > >>>
> >> > > >>> So since you mentioned that things should be working without the
> >> > > >>> configuration i removed it and ran but it still doesnt log the
> >> > details
> >> > > as
> >> > > >>> desired.
> >> > > >>>
> >> > > >>> Is this an issue with log4j2?
> >> > > >>>
> >> > > >>> Regards,
> >> > > >>> -Yogesh
> >> > > >>>
> >> > > >>> On Sunday, August 24, 2014, Ralph Goers <
> >> ralph.go...@dslextreme.com>
> >> > > >>> wrote:
> >> > > >>>
> >> > >  I am really not clear on what the issue is. It seems you have
> >> things
> >> > >  configured so that you can write to the Log4j 2 API but
> actually
> >> use
> >> > > >>> SLF4J
> >> > >  for logging.  There is nothing wrong with that but if you are
> >> > routing
> >> > > >> to
> >> > >  SLF4J and using SLF4J Simple Logger then the Log4j 2
> >> configuration
> >> > > >> won’t
> >> > >  even be used.
> >> > > 
> >> > >  What are you really wanting to do and what are you expecting to
> >> > > happen?
> >> > > 
> >> > >  Ralph
> >> > > 
> >> > >  On Aug 22, 2014, at 7:57 PM, Yogesh Rao  >> > > >>> >
> >> > >  wrote:
> >> > > 
> >> > > > Thanks matt!
> >> > > >
> >> > > > First is what i am attempting to check.. Here instead of
> >> logback i
> >> > > >> have
> >> > > > used slf4j-simple.
> >> > > >
> >> > > > Based on this is there any issue with my implementation?
> >> > > >
> >> > > > Regards,
> >> > > > -Yogesh
> >> > > >
> >> > > > On Friday, August 22, 2014, Matt Sicker  >> > > >>> >
> >> > >  wrote:
> >> > > >
> >> > > >> Using log4j-to-slf4j is for when you want to use log4j-api
> but
> >> > with
> >> > > >> an
> >> > > >> slf4j implementation (like logback). log4j-slf4j-impl would
> >> allow
> >> > > >> you
> >> > > >>> to
> >> > > >> use slf4j-api and have that log to log4j-core.

Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Ralph Goers
That sounds reasonable.

Ralph


On Sep 2, 2014, at 9:41 AM, Yogesh Rao  wrote:

> Hi Ralph,
> 
> IMO new Object[0] as a param value is valid and should behave similar to a
> call to the method without param i.e. logger.error("Hello World {} in {} ");
> 
> In the above context adding a conditional check params.length > 0 with then
> the "if" @ line 157 wouldn't end up throwing the error and print the given
> message
> 
> Regards,
> -Yogesh
> 
> 
> On Tue, Sep 2, 2014 at 9:45 PM, Ralph Goers 
> wrote:
> 
>> What will you do instead of throwing an ArrayIndexOutOfBoundsException?
>> This is obviously a user error.  It would be misleading (but maybe
>> acceptable) to substitute “null” for the placeholders, but just throwing a
>> different exception probably isn’t worth the trouble.
>> 
>> Ralph
>> 
>> On Sep 2, 2014, at 7:24 AM, Yogesh Rao  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
>> 
>> 
>> -
>> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 
>> 


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



Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Yogesh Rao
Hi Ralph,

IMO new Object[0] as a param value is valid and should behave similar to a
call to the method without param i.e. logger.error("Hello World {} in {} ");

In the above context adding a conditional check params.length > 0 with then
the "if" @ line 157 wouldn't end up throwing the error and print the given
message

Regards,
-Yogesh


On Tue, Sep 2, 2014 at 9:45 PM, Ralph Goers 
wrote:

> What will you do instead of throwing an ArrayIndexOutOfBoundsException?
> This is obviously a user error.  It would be misleading (but maybe
> acceptable) to substitute “null” for the placeholders, but just throwing a
> different exception probably isn’t worth the trouble.
>
> Ralph
>
> On Sep 2, 2014, at 7:24 AM, Yogesh Rao  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
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Extending Appenders

2014-09-02 Thread Ralph Goers
After looking at SmtpAppender, SmtpManager and your eamil it doesn’t sound to 
me like there is a lot of benefit in extending SmtpAppender or SmtpManager. 
Their primary purpose of those, and the majority of the code, is to send email 
- which you have said your version doesn’t do. The only code you seem to want 
to reuse is the isFiltered method in the Appender and the CyclicBuffer in the 
Manager which together is a very small amount of code.

If there is some refactoring here that should happen to make what you want 
easier perhaps that should be considered.

Ralph

On Sep 2, 2014, at 9:08 AM, Michael Schall  wrote:

> Thanks for all your input.
> 
> I'm going to try and implement the appender we need to maintain our current
> throttling infrastructure.  I will send a patch with the changes we need as
> far as moving items from private to protected and removing the final
> keyword.
> 
> 
> On Sat, Aug 30, 2014 at 2:02 PM, Matt Sicker  wrote:
> 
>> http://logging.apache.org/log4j/2.x/manual/filters.html#BurstFilter
>> http://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender
>> 
>> There are several ways to go about implementing what you're asking about
>> using existing features. You may be able to get what you need by using just
>> the burst filter and routing appender (which itself may not be required
>> depending on your usage).
>> 
>> 
>> On 30 August 2014 09:27, Jeff Shaw  wrote:
>> 
>>> It sounds like a feature that belongs to any logger. Syslog doesn't need
>>> to know that a database server is unavailable every nanosecond, either.
>>> 
>>> Sent from my phone
>>> 
 On Aug 30, 2014, at 3:19 AM, Remko Popma 
>> wrote:
 
 This sounds like a good feature to have in log4j2. I remember we had an
>>> issue at work where error logs were emailed automatically, bringing down
>>> the mail server when the app kept generating the same error. Painful.
 
 Sent from my iPhone
 
> On 2014/08/30, at 7:24, Michael Schall  wrote:
> 
> Again, thanks for all the interest in my request.
> 
> I don't have the code in front of me, but I will try and give an
> overview of what we did for log4j 1.x.
> 
> We want to send emails for errors happening in production. However for
> example, we don't want to send thousands of emails if the network goes
> down to a database.  If we have an issue that attempts to send more
> than X emails in a timeframe, we want to only send 1 email at high
> priority and "archive" the rest.  If the issue is not resolved we may
> send multiple high priority emails until the issue is resolved, but
> only a fraction of the emails are actually sent.
> 
> We have a standalone service that does all the throttling logic by
> watching a folder for file creations.  So the appender I'm talking
> about writing doesn't actually send emails. It just does everything
> the SmtpAppender does (buffering, evaluating,  ...), but writes a file
> to a "watch" folder instead of sending messages.  The service then
> either sends the mail or throttles and sends at high priority.
> 
> So, my thought is that I would extend the  SmtpAppender and override
> the sendEvents method to write out the contents of the buffer to a
> file.  This approach has worked great with log4j 1.x.
> 
> Mike
> 
>> On Aug 29, 2014, at 11:28 PM, Ralph Goers <
>> ralph.go...@dslextreme.com>
>>> wrote:
>> 
>> This is a fair point.  There are some things not in the API that we
>>> wouldn’t change as they would also break compatibility, such as the
>> Layout
>>> or Appender interface, but we aren’t guaranteeing that specific Appender
>> or
>>> Layout instances won’t have a new parameter added to them or things like
>>> that.
>> 
>> Ralph
>> 
>>> On Aug 29, 2014, at 3:22 PM, Remko Popma 
>>> wrote:
>>> 
>>> I would not object to changing SmtpAppender to make it more
>>> extendible.
>>> 
>>> Can you tell me more about your use case? SmtpAppender is designed
>>> this way
>>> because we had a specific usage in mind. By understanding your use
>>> case we
>>> might be able to improve the design in a way that benefits not just
>>> you but
>>> other users as well. What do you want to do that you can't do with
>> the
>>> current SmtpAppender?
>>> 
>>> Looks like several changes are required. I am away from my PC and
>>> can't
>>> judge the details now. Could you raise a feature request Jira and
>>> attach a
>>> patch that includes all the changes you'd like to make? That might
>>> save us
>>> some going back and forth.
>>> 
>>> Thanks!
>>> Remko
>>> 
 On Friday, August 29, 2014, Michael Schall 
>>> wrote:
 
 Thanks for your response Remko.
 
 Looking into this further, I could duplicate the SmtpAppender code
>>> as it
 really just seems to do plugin work.  The bulk of t

Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Ralph Goers
What will you do instead of throwing an ArrayIndexOutOfBoundsException?  This 
is obviously a user error.  It would be misleading (but maybe acceptable) to 
substitute “null” for the placeholders, but just throwing a different exception 
probably isn’t worth the trouble.

Ralph

On Sep 2, 2014, at 7:24 AM, Yogesh Rao  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


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



Re: Extending Appenders

2014-09-02 Thread Michael Schall
Thanks for all your input.

I'm going to try and implement the appender we need to maintain our current
throttling infrastructure.  I will send a patch with the changes we need as
far as moving items from private to protected and removing the final
keyword.


On Sat, Aug 30, 2014 at 2:02 PM, Matt Sicker  wrote:

> http://logging.apache.org/log4j/2.x/manual/filters.html#BurstFilter
> http://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender
>
> There are several ways to go about implementing what you're asking about
> using existing features. You may be able to get what you need by using just
> the burst filter and routing appender (which itself may not be required
> depending on your usage).
>
>
> On 30 August 2014 09:27, Jeff Shaw  wrote:
>
> > It sounds like a feature that belongs to any logger. Syslog doesn't need
> > to know that a database server is unavailable every nanosecond, either.
> >
> > Sent from my phone
> >
> > > On Aug 30, 2014, at 3:19 AM, Remko Popma 
> wrote:
> > >
> > > This sounds like a good feature to have in log4j2. I remember we had an
> > issue at work where error logs were emailed automatically, bringing down
> > the mail server when the app kept generating the same error. Painful.
> > >
> > > Sent from my iPhone
> > >
> > >> On 2014/08/30, at 7:24, Michael Schall  wrote:
> > >>
> > >> Again, thanks for all the interest in my request.
> > >>
> > >> I don't have the code in front of me, but I will try and give an
> > >> overview of what we did for log4j 1.x.
> > >>
> > >> We want to send emails for errors happening in production. However for
> > >> example, we don't want to send thousands of emails if the network goes
> > >> down to a database.  If we have an issue that attempts to send more
> > >> than X emails in a timeframe, we want to only send 1 email at high
> > >> priority and "archive" the rest.  If the issue is not resolved we may
> > >> send multiple high priority emails until the issue is resolved, but
> > >> only a fraction of the emails are actually sent.
> > >>
> > >> We have a standalone service that does all the throttling logic by
> > >> watching a folder for file creations.  So the appender I'm talking
> > >> about writing doesn't actually send emails. It just does everything
> > >> the SmtpAppender does (buffering, evaluating,  ...), but writes a file
> > >> to a "watch" folder instead of sending messages.  The service then
> > >> either sends the mail or throttles and sends at high priority.
> > >>
> > >> So, my thought is that I would extend the  SmtpAppender and override
> > >> the sendEvents method to write out the contents of the buffer to a
> > >> file.  This approach has worked great with log4j 1.x.
> > >>
> > >> Mike
> > >>
> > >>> On Aug 29, 2014, at 11:28 PM, Ralph Goers <
> ralph.go...@dslextreme.com>
> > wrote:
> > >>>
> > >>> This is a fair point.  There are some things not in the API that we
> > wouldn’t change as they would also break compatibility, such as the
> Layout
> > or Appender interface, but we aren’t guaranteeing that specific Appender
> or
> > Layout instances won’t have a new parameter added to them or things like
> > that.
> > >>>
> > >>> Ralph
> > >>>
> >  On Aug 29, 2014, at 3:22 PM, Remko Popma 
> > wrote:
> > 
> >  I would not object to changing SmtpAppender to make it more
> > extendible.
> > 
> >  Can you tell me more about your use case? SmtpAppender is designed
> > this way
> >  because we had a specific usage in mind. By understanding your use
> > case we
> >  might be able to improve the design in a way that benefits not just
> > you but
> >  other users as well. What do you want to do that you can't do with
> the
> >  current SmtpAppender?
> > 
> >  Looks like several changes are required. I am away from my PC and
> > can't
> >  judge the details now. Could you raise a feature request Jira and
> > attach a
> >  patch that includes all the changes you'd like to make? That might
> > save us
> >  some going back and forth.
> > 
> >  Thanks!
> >  Remko
> > 
> > > On Friday, August 29, 2014, Michael Schall 
> > wrote:
> > >
> > > Thanks for your response Remko.
> > >
> > > Looking into this further, I could duplicate the SmtpAppender code
> > as it
> > > really just seems to do plugin work.  The bulk of the code is in
> the
> > > SmtpManager class which is not marked final. The constructor is
> > marked
> > > protected, however it takes a private class (FactoryData).  I would
> > also
> > > like to override the sendEvents method, but then I run into issues
> > because
> > > the buffer is private.
> > >
> > > Do these changes seem like an issue?
> > >
> > > Mike
> > >
> > >
> > > On Fri, Aug 29, 2014 at 4:51 PM, Remko Popma <
> remko.po...@gmail.com
> > > > wrote:
> > >
> > >> Looks like this class was made final in January 2013. The commit
> > message
> > >> m

Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Yogesh Rao
Create Patch would be way for me then :-) and will get the plugin support
for eclipse

Regards,
-Yogesh


On Tue, Sep 2, 2014 at 8:26 PM, Gary Gregory  wrote:

> The easiest path will be for you to let an IDE (like Eclipse, my favorite)
> generate a patch for you from the Team->Create Patch... dialog.
>
> Depending on your Eclipse set up you might have to install EGit to get git
> support in Eclipse.
>
> Gary
>
>
> On Tue, Sep 2, 2014 at 10:53 AM, Yogesh Rao  wrote:
>
> > Hi Gary,
> >
> > I haven't worked on Git as yet, I think i will provide a diff of the
> files
> > (with Git Master branch) and attach it to JIRA .
> >
> > Alternatively if there any link for creating and submitting Git patches,
> > please do let me know I can provide that as well.
> >
> > Regards,
> > -Yogesh
> >
> >
> > On Tue, Sep 2, 2014 at 8:05 PM, Gary Gregory 
> > wrote:
> >
> > > 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  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: garydgreg...@gmail.com | ggreg...@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > 
> > > JUnit in Action, Second Edition 
> > > Spring Batch in Action 
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
>
>
> --
> E

Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Gary Gregory
The easiest path will be for you to let an IDE (like Eclipse, my favorite)
generate a patch for you from the Team->Create Patch... dialog.

Depending on your Eclipse set up you might have to install EGit to get git
support in Eclipse.

Gary


On Tue, Sep 2, 2014 at 10:53 AM, Yogesh Rao  wrote:

> Hi Gary,
>
> I haven't worked on Git as yet, I think i will provide a diff of the files
> (with Git Master branch) and attach it to JIRA .
>
> Alternatively if there any link for creating and submitting Git patches,
> please do let me know I can provide that as well.
>
> Regards,
> -Yogesh
>
>
> On Tue, Sep 2, 2014 at 8:05 PM, Gary Gregory 
> wrote:
>
> > 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  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: garydgreg...@gmail.com | ggreg...@apache.org
> > Java Persistence with Hibernate, Second Edition
> > 
> > JUnit in Action, Second Edition 
> > Spring Batch in Action 
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>



-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition

JUnit in Action, Second Edition 
Spring Batch in Action 
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Yogesh Rao
Hi Gary,

I haven't worked on Git as yet, I think i will provide a diff of the files
(with Git Master branch) and attach it to JIRA .

Alternatively if there any link for creating and submitting Git patches,
please do let me know I can provide that as well.

Regards,
-Yogesh


On Tue, Sep 2, 2014 at 8:05 PM, Gary Gregory  wrote:

> 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  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: garydgreg...@gmail.com | ggreg...@apache.org
> Java Persistence with Hibernate, Second Edition
> 
> JUnit in Action, Second Edition 
> Spring Batch in Action 
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>


Re: Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Gary Gregory
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  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: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition

JUnit in Action, Second Edition 
Spring Batch in Action 
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


Re: Log4j2 with SL4J Adapter

2014-09-02 Thread Yogesh Rao
Hi,

Just an update on this... i had little time last week to work on this
issue. I am looking into this now and checking if a sandbox can be created
for execution of the test cases using class loaders.

Thank you!

Regards,
-Yogesh


On Mon, Aug 25, 2014 at 10:48 AM, Yogesh Rao  wrote:

> Sure Remko! Will try for it.
>
> Thank you!
>
> Regards,
> -Yogesh
>
> On Monday, August 25, 2014, Remko Popma  wrote:
>
>> Great, thank you! I'll have limited PC access the next ten days or so.
>> If you want to take a stab at providing a patch that includes both a JUnit
>> test and a fix, go for it!
>>
>>
>> On Sun, Aug 24, 2014 at 11:31 PM, Yogesh Rao  wrote:
>>
>> > Defect logged under LOG4J2-796
>> >
>> > Regards,
>> > -Yogesh
>> >
>> >
>> > On Sun, Aug 24, 2014 at 2:41 PM, Remko Popma 
>> > wrote:
>> >
>> > > Yogesh,
>> > >
>> > > Thanks! Both would be really helpful!
>> > >
>> > > Remko
>> > >
>> > > Sent from my iPhone
>> > >
>> > > > On 2014/08/24, at 9:09, Yogesh Rao  wrote:
>> > > >
>> > > > Thanks Remko!
>> > > >
>> > > > would you like me to create a JIRA ticket for the same ? I could
>> also
>> > try
>> > > > giving a shot at creating that unit test case for you..
>> > > >
>> > > > Regards,
>> > > > -Yogesh
>> > > >
>> > > >
>> > > >> On Sun, Aug 24, 2014 at 12:35 PM, Remko Popma <
>> remko.po...@gmail.com>
>> > > wrote:
>> > > >>
>> > > >> This looks like a bug. The output is the FQCN (fully qualified
>> name of
>> > > the
>> > > >> logger).
>> > > >> This is probably introduced by the changes made for LOG4J2-555.
>> > > >>
>> > > >> Our unit tests are not picking this up because they use
>> > > >> the ch.qos.logback.classic.Logger, which is a LocationAwareLogger
>> and
>> > > >> follows a different code path.
>> > > >> I suspect that Simple Logger is not LocationAware.
>> > > >>
>> > > >> I suspect we should change (in SLF4JLogger.logMessage)
>> > > >> logger.debug(fqcn, getMarker(marker),
>> > message.getFormattedMessage(),
>> > > >> message.getParameters(), t);
>> > > >> to
>> > > >> logger.debug(getMarker(marker), message.getFormattedMessage(),
>> > > >> message.getParameters(), t);
>> > > >>
>> > > >> I can change this but want to make a failing unit test first and I
>> > > haven't
>> > > >> had time to figure out how to do that yet.
>> > > >>
>> > > >>
>> > > >>
>> > > >>> On Sun, Aug 24, 2014 at 12:00 PM, Yogesh Rao 
>> > wrote:
>> > > >>>
>> > > >>> Hi Ralph,
>> > > >>>
>> > > >>> The issue for me is log4j2 to slf4j adaptor doesnt seem to be
>> > working.
>> > > I
>> > > >>> added the log4j configuration only when the logger wasnt working
>> > hence
>> > > i
>> > > >>> mentioned in brackets that i wasnt sure if its needed or not..
>> > > >>>
>> > > >>> So since you mentioned that things should be working without the
>> > > >>> configuration i removed it and ran but it still doesnt log the
>> > details
>> > > as
>> > > >>> desired.
>> > > >>>
>> > > >>> Is this an issue with log4j2?
>> > > >>>
>> > > >>> Regards,
>> > > >>> -Yogesh
>> > > >>>
>> > > >>> On Sunday, August 24, 2014, Ralph Goers <
>> ralph.go...@dslextreme.com>
>> > > >>> wrote:
>> > > >>>
>> > >  I am really not clear on what the issue is. It seems you have
>> things
>> > >  configured so that you can write to the Log4j 2 API but actually
>> use
>> > > >>> SLF4J
>> > >  for logging.  There is nothing wrong with that but if you are
>> > routing
>> > > >> to
>> > >  SLF4J and using SLF4J Simple Logger then the Log4j 2
>> configuration
>> > > >> won’t
>> > >  even be used.
>> > > 
>> > >  What are you really wanting to do and what are you expecting to
>> > > happen?
>> > > 
>> > >  Ralph
>> > > 
>> > >  On Aug 22, 2014, at 7:57 PM, Yogesh Rao > > > >>> >
>> > >  wrote:
>> > > 
>> > > > Thanks matt!
>> > > >
>> > > > First is what i am attempting to check.. Here instead of
>> logback i
>> > > >> have
>> > > > used slf4j-simple.
>> > > >
>> > > > Based on this is there any issue with my implementation?
>> > > >
>> > > > Regards,
>> > > > -Yogesh
>> > > >
>> > > > On Friday, August 22, 2014, Matt Sicker > > > >>> >
>> > >  wrote:
>> > > >
>> > > >> Using log4j-to-slf4j is for when you want to use log4j-api but
>> > with
>> > > >> an
>> > > >> slf4j implementation (like logback). log4j-slf4j-impl would
>> allow
>> > > >> you
>> > > >>> to
>> > > >> use slf4j-api and have that log to log4j-core.
>> > > >>
>> > > >>
>> > > >> On 22 August 2014 08:27, Yogesh Rao > > > >> 
>> > >  >
>> > > >> wrote:
>> > > >>
>> > > >>> Hi,
>> > > >>>
>> > > >>> I am trying out the API side of log4j2 with the SLF4J adaptor.
>> > With
>> > > >>> the
>> > > >>> sample code written i couldn't see the logging being done
>> > properly.
>> > > >> Perhaps
>> > > >>> i am doing something wrong here.
>> > > >>>
>> > > >>> Firstly versions of the software are :-
>> > > >>>
>> > > >>> 1. 

Log4j2's SimpleLogger Implementation Issue for var args method's

2014-09-02 Thread Yogesh Rao
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