Re: looking for source

2016-11-05 Thread Ralph Goers
If you look at PatternLayout you will see a few choices for how the Exception 
gets formatted. %ex uses printStackTrace to format the Exception, however that 
is not the default. We extend the stack trace to also include the source of 
each class (i.e. the jar or class directory) and its version, if it can be 
determined. Other Layouts may, or may not, format the Exception depending on 
what they are attempting to do. 

To take this further, there are many components that make up the log event - 
the level, Marker, message (with or without parameters), time, ThreadContext 
values, logger name, class name, method name, line number and the exception. 
Each of these are discrete values that the Layout can format (or not) as it 
chooses.

Ralph

> On Nov 5, 2016, at 6:33 PM, Nicholas Duane  wrote:
> 
> Thanks.  I have no problem doing that.  Just wondering what needs to be done 
> and how?  I guess I was hoping that the logging framework, eg. log4j, handled 
> combining the message and the exception such that no matter what 
> appender/layout you used you'd get consistent results.  Sounds like that's 
> not the case.  So are you saying I need to combine the message and the 
> exception myself within our appender/layout?
> 
> 
> From the code I included below you can see we're doing:
> 
> 
> String message = logEvent.getMessage().getFormattedMessage();
> 
> 
> to get the event's message.  Are you saying we should be doing something like 
> this:
> 
> 
> StringWriter sw = new StringWriter();
> logEvent.getThrown().printStackTrace(new PrintWriter(sw));
> String exceptionAsString = sw.toString();
> String message = logEvent.getMessage().getFormattedMessage() + "\n" + 
> exceptionAsString;
> 
> 
> Thanks,
> 
> Nick
> 
> 
> From: Remko Popma >
> Sent: Saturday, November 5, 2016 9:16 PM
> To: Log4J Users List
> Subject: Re: looking for source
> 
> The point is that in a custom layout/appender you should get the throwable 
> from the LogEvent, not from the Message. That is the design that all Layouts 
> and Appenders follow and should follow.
> 
> The Message object passed to the Layout may no longer have the Throwable.
> 
> Sent from my iPhone
> 
>> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
>> 
>> Thanks for the info.  Unfortunately I'm not following.  If someone can point 
>> me to the source in question I will certainly look it over.  My sample 
>> outputs the message (%msg) and when the method logger.error(String message, 
>> Throwable t) is called it seems some code is combining the supplied string 
>> message with the exception message and stack trace.  Just wondering what 
>> code is doing that as I'm told someone using our appender/layout is not 
>> seeing the exception.
>> 
>> 
>> Thanks,
>> 
>> Nick
>> 
>> 
>> From: Remko Popma 
>> Sent: Friday, November 4, 2016 9:58 PM
>> To: Log4J Users List
>> Subject: Re: looking for source
>> 
>> The Throwable is initially captured in the Message (usually 
>> ParameterizedMessage or its garbage-free equivalent), but is later 
>> transferred to the LogEvent.
>> 
>> By the time the LogEvent reaches the Layout, the Message instance may be a 
>> different Object than the one that originally held the Throwable.
>> 
>> The Layout should get the Throwable from the LogEvent, not from the Message.
>> 
>> Remko
>> 
>> Sent from my iPhone
>> 
>>> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>>> 
>>> Thanks for the replies.  Let me ask a more pointed question now as 
>>> rummaging through the source will probably take me hours.  I'm curious 
>>> about the overloads with the throwable, for instance:
>>> 
>>> 
>>> logger.error("some message", );
>>> 
>>> 
>>> What's the expected behavior?  Meaning, what is the logging framework going 
>>> to do with the message and the exception?  I know the message is usually 
>>> output via the message property in the pattern layout.  But what happens 
>>> with the throwable?  Is there some code responsible for constructing a 
>>> message which combines the supplied message with the throwable exception 
>>> message and callstack?
>>> 
>>> 
>>> I wrote the following simple java sample:
>>> 
>>> 
>>> import org.apache.logging.log4j.Logger;
>>> import org.apache.logging.log4j.LogManager;
>>> 
>>> public class Test
>>> {
>>>  private static final Logger logger = LogManager.getLogger(Test.class);
>>> 
>>>  public static void main(String[] args)
>>>  {
>>>   logger.info("entered main");
>>>  try
>>>  {
>>>  throw(new IllegalArgumentException("bad argument"));
>>>  }
>>>  catch(Throwable t)
>>>  {
>>>  logger.error("caught exception", t);
>>>  }
>>>  logger.info("exiting main");
>>>  }
>>> }
>>> 
>>> 
>>> Here is the log4j2.xml file:
>>> 
>>> 
>>> 
>>> 
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  

Re: looking for source

2016-11-05 Thread Remko Popma
I will update the javadoc on the LogEvent interface to mention that Layouts and 
Appenders should get the Throwable from the event and that the Message object 
may not be the instance initially used in the Logger API to capture the message 
parameters and Throwable. 

Sent from my iPhone

> On 6 Nov 2016, at 11:16, Nicholas Duane  wrote:
> 
> Thanks, I'll check out the link you provided.
> 
> 
> I guess since log4j2 exposes:
> 
> 
> logger.error(String message);
> 
> 
> and
> 
> 
> logger.error(String message, Throwable t);
> 
> 
> As well as a bunch of others, I wasn't sure if it was the logging framework 
> that did the work of composing a single message out of the parameters to the 
> call.  Otherwise you'll get different behavior using different 
> appender/layout, as we're seeing with our appender/layout.
> 
> 
> Thanks,
> 
> Nick
> 
> 
> From: Remko Popma 
> Sent: Saturday, November 5, 2016 10:03 PM
> To: Log4J Users List
> Subject: Re: looking for source
> 
> Nick,
> 
> If you want to combine the formatted message string and the stack trace into 
> a single string in your layout then yes, that is one way to do that.
> 
> For reference, take a look at the MessagePatternConverter and 
> ThrowablePatternConverter (used by Log4j's PatternLayout): 
> https://github.com/apache/logging-log4j2/tree/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern
> 
> Conceptually the Message and the Throwable are separate parts of the 
> LogEvent. I think what may have caused some confusion is that initially 
> ParameterizedMessage captures message parameters and the Throwable in a 
> single vararg array, but please consider that an implementation detail.
> 
> Sent from my iPhone
> 
>> On 6 Nov 2016, at 10:33, Nicholas Duane  wrote:
>> 
>> Thanks.  I have no problem doing that.  Just wondering what needs to be done 
>> and how?  I guess I was hoping that the logging framework, eg. log4j, 
>> handled combining the message and the exception such that no matter what 
>> appender/layout you used you'd get consistent results.  Sounds like that's 
>> not the case.  So are you saying I need to combine the message and the 
>> exception myself within our appender/layout?
>> 
>> 
>> From the code I included below you can see we're doing:
>> 
>> 
>> String message = logEvent.getMessage().getFormattedMessage();
>> 
>> 
>> to get the event's message.  Are you saying we should be doing something 
>> like this:
>> 
>> 
>> StringWriter sw = new StringWriter();
>> logEvent.getThrown().printStackTrace(new PrintWriter(sw));
>> String exceptionAsString = sw.toString();
>> String message = logEvent.getMessage().getFormattedMessage() + "\n" + 
>> exceptionAsString;
>> 
>> 
>> Thanks,
>> 
>> Nick
>> 
>> 
>> From: Remko Popma 
>> Sent: Saturday, November 5, 2016 9:16 PM
>> To: Log4J Users List
>> Subject: Re: looking for source
>> 
>> The point is that in a custom layout/appender you should get the throwable 
>> from the LogEvent, not from the Message. That is the design that all Layouts 
>> and Appenders follow and should follow.
>> 
>> The Message object passed to the Layout may no longer have the Throwable.
>> 
>> Sent from my iPhone
>> 
>>> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
>>> 
>>> Thanks for the info.  Unfortunately I'm not following.  If someone can 
>>> point me to the source in question I will certainly look it over.  My 
>>> sample outputs the message (%msg) and when the method logger.error(String 
>>> message, Throwable t) is called it seems some code is combining the 
>>> supplied string message with the exception message and stack trace.  Just 
>>> wondering what code is doing that as I'm told someone using our 
>>> appender/layout is not seeing the exception.
>>> 
>>> 
>>> Thanks,
>>> 
>>> Nick
>>> 
>>> 
>>> From: Remko Popma 
>>> Sent: Friday, November 4, 2016 9:58 PM
>>> To: Log4J Users List
>>> Subject: Re: looking for source
>>> 
>>> The Throwable is initially captured in the Message (usually 
>>> ParameterizedMessage or its garbage-free equivalent), but is later 
>>> transferred to the LogEvent.
>>> 
>>> By the time the LogEvent reaches the Layout, the Message instance may be a 
>>> different Object than the one that originally held the Throwable.
>>> 
>>> The Layout should get the Throwable from the LogEvent, not from the Message.
>>> 
>>> Remko
>>> 
>>> Sent from my iPhone
>>> 
 On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
 
 Thanks for the replies.  Let me ask a more pointed question now as 
 rummaging through the source will probably take me hours.  I'm curious 
 about the overloads with the throwable, for instance:
 
 
 logger.error("some message", );
 
 
 What's the expected behavior?  Meaning, what is the logging 

Re: looking for source

2016-11-05 Thread Nicholas Duane
Thanks, I'll check out the link you provided.


I guess since log4j2 exposes:


logger.error(String message);


and


logger.error(String message, Throwable t);


As well as a bunch of others, I wasn't sure if it was the logging framework 
that did the work of composing a single message out of the parameters to the 
call.  Otherwise you'll get different behavior using different appender/layout, 
as we're seeing with our appender/layout.


Thanks,

Nick


From: Remko Popma 
Sent: Saturday, November 5, 2016 10:03 PM
To: Log4J Users List
Subject: Re: looking for source

Nick,

If you want to combine the formatted message string and the stack trace into a 
single string in your layout then yes, that is one way to do that.

For reference, take a look at the MessagePatternConverter and 
ThrowablePatternConverter (used by Log4j's PatternLayout): 
https://github.com/apache/logging-log4j2/tree/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern

Conceptually the Message and the Throwable are separate parts of the LogEvent. 
I think what may have caused some confusion is that initially 
ParameterizedMessage captures message parameters and the Throwable in a single 
vararg array, but please consider that an implementation detail.

Sent from my iPhone

> On 6 Nov 2016, at 10:33, Nicholas Duane  wrote:
>
> Thanks.  I have no problem doing that.  Just wondering what needs to be done 
> and how?  I guess I was hoping that the logging framework, eg. log4j, handled 
> combining the message and the exception such that no matter what 
> appender/layout you used you'd get consistent results.  Sounds like that's 
> not the case.  So are you saying I need to combine the message and the 
> exception myself within our appender/layout?
>
>
> From the code I included below you can see we're doing:
>
>
> String message = logEvent.getMessage().getFormattedMessage();
>
>
> to get the event's message.  Are you saying we should be doing something like 
> this:
>
>
> StringWriter sw = new StringWriter();
> logEvent.getThrown().printStackTrace(new PrintWriter(sw));
> String exceptionAsString = sw.toString();
> String message = logEvent.getMessage().getFormattedMessage() + "\n" + 
> exceptionAsString;
>
>
> Thanks,
>
> Nick
>
> 
> From: Remko Popma 
> Sent: Saturday, November 5, 2016 9:16 PM
> To: Log4J Users List
> Subject: Re: looking for source
>
> The point is that in a custom layout/appender you should get the throwable 
> from the LogEvent, not from the Message. That is the design that all Layouts 
> and Appenders follow and should follow.
>
> The Message object passed to the Layout may no longer have the Throwable.
>
> Sent from my iPhone
>
>> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
>>
>> Thanks for the info.  Unfortunately I'm not following.  If someone can point 
>> me to the source in question I will certainly look it over.  My sample 
>> outputs the message (%msg) and when the method logger.error(String message, 
>> Throwable t) is called it seems some code is combining the supplied string 
>> message with the exception message and stack trace.  Just wondering what 
>> code is doing that as I'm told someone using our appender/layout is not 
>> seeing the exception.
>>
>>
>> Thanks,
>>
>> Nick
>>
>> 
>> From: Remko Popma 
>> Sent: Friday, November 4, 2016 9:58 PM
>> To: Log4J Users List
>> Subject: Re: looking for source
>>
>> The Throwable is initially captured in the Message (usually 
>> ParameterizedMessage or its garbage-free equivalent), but is later 
>> transferred to the LogEvent.
>>
>> By the time the LogEvent reaches the Layout, the Message instance may be a 
>> different Object than the one that originally held the Throwable.
>>
>> The Layout should get the Throwable from the LogEvent, not from the Message.
>>
>> Remko
>>
>> Sent from my iPhone
>>
>>> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>>>
>>> Thanks for the replies.  Let me ask a more pointed question now as 
>>> rummaging through the source will probably take me hours.  I'm curious 
>>> about the overloads with the throwable, for instance:
>>>
>>>
>>> logger.error("some message", );
>>>
>>>
>>> What's the expected behavior?  Meaning, what is the logging framework going 
>>> to do with the message and the exception?  I know the message is usually 
>>> output via the message property in the pattern layout.  But what happens 
>>> with the throwable?  Is there some code responsible for constructing a 
>>> message which combines the supplied message with the throwable exception 
>>> message and callstack?
>>>
>>>
>>> I wrote the following simple java sample:
>>>
>>>
>>> import org.apache.logging.log4j.Logger;
>>> import org.apache.logging.log4j.LogManager;
>>>
>>> public class Test
>>> {
>>>  private static final Logger logger 

Re: looking for source

2016-11-05 Thread Remko Popma
Nick,

If you want to combine the formatted message string and the stack trace into a 
single string in your layout then yes, that is one way to do that. 

For reference, take a look at the MessagePatternConverter and 
ThrowablePatternConverter (used by Log4j's PatternLayout): 
https://github.com/apache/logging-log4j2/tree/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern

Conceptually the Message and the Throwable are separate parts of the LogEvent. 
I think what may have caused some confusion is that initially 
ParameterizedMessage captures message parameters and the Throwable in a single 
vararg array, but please consider that an implementation detail. 

Sent from my iPhone

> On 6 Nov 2016, at 10:33, Nicholas Duane  wrote:
> 
> Thanks.  I have no problem doing that.  Just wondering what needs to be done 
> and how?  I guess I was hoping that the logging framework, eg. log4j, handled 
> combining the message and the exception such that no matter what 
> appender/layout you used you'd get consistent results.  Sounds like that's 
> not the case.  So are you saying I need to combine the message and the 
> exception myself within our appender/layout?
> 
> 
> From the code I included below you can see we're doing:
> 
> 
> String message = logEvent.getMessage().getFormattedMessage();
> 
> 
> to get the event's message.  Are you saying we should be doing something like 
> this:
> 
> 
> StringWriter sw = new StringWriter();
> logEvent.getThrown().printStackTrace(new PrintWriter(sw));
> String exceptionAsString = sw.toString();
> String message = logEvent.getMessage().getFormattedMessage() + "\n" + 
> exceptionAsString;
> 
> 
> Thanks,
> 
> Nick
> 
> 
> From: Remko Popma 
> Sent: Saturday, November 5, 2016 9:16 PM
> To: Log4J Users List
> Subject: Re: looking for source
> 
> The point is that in a custom layout/appender you should get the throwable 
> from the LogEvent, not from the Message. That is the design that all Layouts 
> and Appenders follow and should follow.
> 
> The Message object passed to the Layout may no longer have the Throwable.
> 
> Sent from my iPhone
> 
>> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
>> 
>> Thanks for the info.  Unfortunately I'm not following.  If someone can point 
>> me to the source in question I will certainly look it over.  My sample 
>> outputs the message (%msg) and when the method logger.error(String message, 
>> Throwable t) is called it seems some code is combining the supplied string 
>> message with the exception message and stack trace.  Just wondering what 
>> code is doing that as I'm told someone using our appender/layout is not 
>> seeing the exception.
>> 
>> 
>> Thanks,
>> 
>> Nick
>> 
>> 
>> From: Remko Popma 
>> Sent: Friday, November 4, 2016 9:58 PM
>> To: Log4J Users List
>> Subject: Re: looking for source
>> 
>> The Throwable is initially captured in the Message (usually 
>> ParameterizedMessage or its garbage-free equivalent), but is later 
>> transferred to the LogEvent.
>> 
>> By the time the LogEvent reaches the Layout, the Message instance may be a 
>> different Object than the one that originally held the Throwable.
>> 
>> The Layout should get the Throwable from the LogEvent, not from the Message.
>> 
>> Remko
>> 
>> Sent from my iPhone
>> 
>>> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>>> 
>>> Thanks for the replies.  Let me ask a more pointed question now as 
>>> rummaging through the source will probably take me hours.  I'm curious 
>>> about the overloads with the throwable, for instance:
>>> 
>>> 
>>> logger.error("some message", );
>>> 
>>> 
>>> What's the expected behavior?  Meaning, what is the logging framework going 
>>> to do with the message and the exception?  I know the message is usually 
>>> output via the message property in the pattern layout.  But what happens 
>>> with the throwable?  Is there some code responsible for constructing a 
>>> message which combines the supplied message with the throwable exception 
>>> message and callstack?
>>> 
>>> 
>>> I wrote the following simple java sample:
>>> 
>>> 
>>> import org.apache.logging.log4j.Logger;
>>> import org.apache.logging.log4j.LogManager;
>>> 
>>> public class Test
>>> {
>>>  private static final Logger logger = LogManager.getLogger(Test.class);
>>> 
>>>  public static void main(String[] args)
>>>  {
>>>   logger.info("entered main");
>>>  try
>>>  {
>>>  throw(new IllegalArgumentException("bad argument"));
>>>  }
>>>  catch(Throwable t)
>>>  {
>>>  logger.error("caught exception", t);
>>>  }
>>>  logger.info("exiting main");
>>>  }
>>> }
>>> 
>>> 
>>> Here is the log4j2.xml file:
>>> 
>>> 
>>> 
>>> 
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>> 
>>> 
>>> 
>>> Here is the output to the console 

Re: looking for source

2016-11-05 Thread Nicholas Duane
Thanks.  I have no problem doing that.  Just wondering what needs to be done 
and how?  I guess I was hoping that the logging framework, eg. log4j, handled 
combining the message and the exception such that no matter what 
appender/layout you used you'd get consistent results.  Sounds like that's not 
the case.  So are you saying I need to combine the message and the exception 
myself within our appender/layout?


>From the code I included below you can see we're doing:


String message = logEvent.getMessage().getFormattedMessage();


to get the event's message.  Are you saying we should be doing something like 
this:


StringWriter sw = new StringWriter();
logEvent.getThrown().printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
String message = logEvent.getMessage().getFormattedMessage() + "\n" + 
exceptionAsString;


Thanks,

Nick


From: Remko Popma 
Sent: Saturday, November 5, 2016 9:16 PM
To: Log4J Users List
Subject: Re: looking for source

The point is that in a custom layout/appender you should get the throwable from 
the LogEvent, not from the Message. That is the design that all Layouts and 
Appenders follow and should follow.

The Message object passed to the Layout may no longer have the Throwable.

Sent from my iPhone

> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
>
> Thanks for the info.  Unfortunately I'm not following.  If someone can point 
> me to the source in question I will certainly look it over.  My sample 
> outputs the message (%msg) and when the method logger.error(String message, 
> Throwable t) is called it seems some code is combining the supplied string 
> message with the exception message and stack trace.  Just wondering what code 
> is doing that as I'm told someone using our appender/layout is not seeing the 
> exception.
>
>
> Thanks,
>
> Nick
>
> 
> From: Remko Popma 
> Sent: Friday, November 4, 2016 9:58 PM
> To: Log4J Users List
> Subject: Re: looking for source
>
> The Throwable is initially captured in the Message (usually 
> ParameterizedMessage or its garbage-free equivalent), but is later 
> transferred to the LogEvent.
>
> By the time the LogEvent reaches the Layout, the Message instance may be a 
> different Object than the one that originally held the Throwable.
>
> The Layout should get the Throwable from the LogEvent, not from the Message.
>
> Remko
>
> Sent from my iPhone
>
>> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>>
>> Thanks for the replies.  Let me ask a more pointed question now as rummaging 
>> through the source will probably take me hours.  I'm curious about the 
>> overloads with the throwable, for instance:
>>
>>
>> logger.error("some message", );
>>
>>
>> What's the expected behavior?  Meaning, what is the logging framework going 
>> to do with the message and the exception?  I know the message is usually 
>> output via the message property in the pattern layout.  But what happens 
>> with the throwable?  Is there some code responsible for constructing a 
>> message which combines the supplied message with the throwable exception 
>> message and callstack?
>>
>>
>> I wrote the following simple java sample:
>>
>>
>> import org.apache.logging.log4j.Logger;
>> import org.apache.logging.log4j.LogManager;
>>
>> public class Test
>> {
>>   private static final Logger logger = LogManager.getLogger(Test.class);
>>
>>   public static void main(String[] args)
>>   {
>>logger.info("entered main");
>>   try
>>   {
>>   throw(new IllegalArgumentException("bad argument"));
>>   }
>>   catch(Throwable t)
>>   {
>>   logger.error("caught exception", t);
>>   }
>>   logger.info("exiting main");
>>   }
>> }
>>
>>
>> Here is the log4j2.xml file:
>>
>>
>> 
>> 
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>> 
>>
>>
>> Here is the output to the console when I run the sample:
>>
>>
>> [nick@thinkpad log4j]$ java Test
>> 16:37:57.681 [main] INFO  Test - entered main
>> 16:37:57.683 [main] ERROR Test - caught exception
>> java.lang.IllegalArgumentException: bad argument
>>   at Test.main(Test.java:13) [log4j/:?]
>> 16:37:57.689 [main] INFO  Test - exiting main
>>
>>
>> So there does seem to be some code which is combining the message with the 
>> exception.  Just wondering where that happens.  Now onto my specific 
>> problem.  We've got someone saying that when they use the error() method 
>> which takes a string message and an throwable the exception information is 
>> not making it to our central repository.  We have written our own appender 
>> and our own layout.  Here is a snippet from our appender:
>>
>>
>> String serializedEvent = (String) getLayout().toSerializable(logEvent);
>>
>> Here is a snippet from our layout:
>>
>>
>> String message = logEvent.getMessage().getFormattedMessage();
>>
>>

Re: looking for source

2016-11-05 Thread Remko Popma
The point is that in a custom layout/appender you should get the throwable from 
the LogEvent, not from the Message. That is the design that all Layouts and 
Appenders follow and should follow. 

The Message object passed to the Layout may no longer have the Throwable. 

Sent from my iPhone

> On 6 Nov 2016, at 10:01, Nicholas Duane  wrote:
> 
> Thanks for the info.  Unfortunately I'm not following.  If someone can point 
> me to the source in question I will certainly look it over.  My sample 
> outputs the message (%msg) and when the method logger.error(String message, 
> Throwable t) is called it seems some code is combining the supplied string 
> message with the exception message and stack trace.  Just wondering what code 
> is doing that as I'm told someone using our appender/layout is not seeing the 
> exception.
> 
> 
> Thanks,
> 
> Nick
> 
> 
> From: Remko Popma 
> Sent: Friday, November 4, 2016 9:58 PM
> To: Log4J Users List
> Subject: Re: looking for source
> 
> The Throwable is initially captured in the Message (usually 
> ParameterizedMessage or its garbage-free equivalent), but is later 
> transferred to the LogEvent.
> 
> By the time the LogEvent reaches the Layout, the Message instance may be a 
> different Object than the one that originally held the Throwable.
> 
> The Layout should get the Throwable from the LogEvent, not from the Message.
> 
> Remko
> 
> Sent from my iPhone
> 
>> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>> 
>> Thanks for the replies.  Let me ask a more pointed question now as rummaging 
>> through the source will probably take me hours.  I'm curious about the 
>> overloads with the throwable, for instance:
>> 
>> 
>> logger.error("some message", );
>> 
>> 
>> What's the expected behavior?  Meaning, what is the logging framework going 
>> to do with the message and the exception?  I know the message is usually 
>> output via the message property in the pattern layout.  But what happens 
>> with the throwable?  Is there some code responsible for constructing a 
>> message which combines the supplied message with the throwable exception 
>> message and callstack?
>> 
>> 
>> I wrote the following simple java sample:
>> 
>> 
>> import org.apache.logging.log4j.Logger;
>> import org.apache.logging.log4j.LogManager;
>> 
>> public class Test
>> {
>>   private static final Logger logger = LogManager.getLogger(Test.class);
>> 
>>   public static void main(String[] args)
>>   {
>>logger.info("entered main");
>>   try
>>   {
>>   throw(new IllegalArgumentException("bad argument"));
>>   }
>>   catch(Throwable t)
>>   {
>>   logger.error("caught exception", t);
>>   }
>>   logger.info("exiting main");
>>   }
>> }
>> 
>> 
>> Here is the log4j2.xml file:
>> 
>> 
>> 
>> 
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>>   
>> 
>> 
>> 
>> Here is the output to the console when I run the sample:
>> 
>> 
>> [nick@thinkpad log4j]$ java Test
>> 16:37:57.681 [main] INFO  Test - entered main
>> 16:37:57.683 [main] ERROR Test - caught exception
>> java.lang.IllegalArgumentException: bad argument
>>   at Test.main(Test.java:13) [log4j/:?]
>> 16:37:57.689 [main] INFO  Test - exiting main
>> 
>> 
>> So there does seem to be some code which is combining the message with the 
>> exception.  Just wondering where that happens.  Now onto my specific 
>> problem.  We've got someone saying that when they use the error() method 
>> which takes a string message and an throwable the exception information is 
>> not making it to our central repository.  We have written our own appender 
>> and our own layout.  Here is a snippet from our appender:
>> 
>> 
>> String serializedEvent = (String) getLayout().toSerializable(logEvent);
>> 
>> Here is a snippet from our layout:
>> 
>> 
>> String message = logEvent.getMessage().getFormattedMessage();
>> 
>> 
>> It seems the message above does not include any exception info.  What are we 
>> doing wrong?
>> 
>> 
>> Thanks,
>> 
>> Nick
>> 
>> 
>> From: Remko Popma 
>> Sent: Friday, November 4, 2016 10:42 AM
>> To: Log4J Users List
>> Subject: Re: looking for source
>> 
>> Sure. Start in AbstractLogger in the API module: 
>> https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
> [https://avatars1.githubusercontent.com/u/47359?v=3=400]
> 
> apache/logging-log4j2
> github.com
> logging-log4j2 - Mirror of Apache Logging Log4J2
> 
> 
>> 
>> and at some point you probably also want to look at the concrete subclass 
>> Logger 

Re: looking for source

2016-11-05 Thread Nicholas Duane
Thanks for the info.  Unfortunately I'm not following.  If someone can point me 
to the source in question I will certainly look it over.  My sample outputs the 
message (%msg) and when the method logger.error(String message, Throwable t) is 
called it seems some code is combining the supplied string message with the 
exception message and stack trace.  Just wondering what code is doing that as 
I'm told someone using our appender/layout is not seeing the exception.


Thanks,

Nick


From: Remko Popma 
Sent: Friday, November 4, 2016 9:58 PM
To: Log4J Users List
Subject: Re: looking for source

The Throwable is initially captured in the Message (usually 
ParameterizedMessage or its garbage-free equivalent), but is later transferred 
to the LogEvent.

By the time the LogEvent reaches the Layout, the Message instance may be a 
different Object than the one that originally held the Throwable.

The Layout should get the Throwable from the LogEvent, not from the Message.

Remko

Sent from my iPhone

> On 5 Nov 2016, at 7:50,Nicholas Duane  wrote:
>
> Thanks for the replies.  Let me ask a more pointed question now as rummaging 
> through the source will probably take me hours.  I'm curious about the 
> overloads with the throwable, for instance:
>
>
> logger.error("some message", );
>
>
> What's the expected behavior?  Meaning, what is the logging framework going 
> to do with the message and the exception?  I know the message is usually 
> output via the message property in the pattern layout.  But what happens with 
> the throwable?  Is there some code responsible for constructing a message 
> which combines the supplied message with the throwable exception message and 
> callstack?
>
>
> I wrote the following simple java sample:
>
>
> import org.apache.logging.log4j.Logger;
> import org.apache.logging.log4j.LogManager;
>
> public class Test
> {
>private static final Logger logger = LogManager.getLogger(Test.class);
>
>public static void main(String[] args)
>{
> logger.info("entered main");
>try
>{
>throw(new IllegalArgumentException("bad argument"));
>}
>catch(Throwable t)
>{
>logger.error("caught exception", t);
>}
>logger.info("exiting main");
>}
> }
>
>
> Here is the log4j2.xml file:
>
>
> 
> 
>
>
>
>
>
>
>
>
>
>
> 
>
>
> Here is the output to the console when I run the sample:
>
>
> [nick@thinkpad log4j]$ java Test
> 16:37:57.681 [main] INFO  Test - entered main
> 16:37:57.683 [main] ERROR Test - caught exception
> java.lang.IllegalArgumentException: bad argument
>at Test.main(Test.java:13) [log4j/:?]
> 16:37:57.689 [main] INFO  Test - exiting main
>
>
> So there does seem to be some code which is combining the message with the 
> exception.  Just wondering where that happens.  Now onto my specific problem. 
>  We've got someone saying that when they use the error() method which takes a 
> string message and an throwable the exception information is not making it to 
> our central repository.  We have written our own appender and our own layout. 
>  Here is a snippet from our appender:
>
>
> String serializedEvent = (String) getLayout().toSerializable(logEvent);
>
> Here is a snippet from our layout:
>
>
> String message = logEvent.getMessage().getFormattedMessage();
>
>
> It seems the message above does not include any exception info.  What are we 
> doing wrong?
>
>
> Thanks,
>
> Nick
>
> 
> From: Remko Popma 
> Sent: Friday, November 4, 2016 10:42 AM
> To: Log4J Users List
> Subject: Re: looking for source
>
> Sure. Start in AbstractLogger in the API module: 
> https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
[https://avatars1.githubusercontent.com/u/47359?v=3=400]

apache/logging-log4j2
github.com
logging-log4j2 - Mirror of Apache Logging Log4J2


>
> and at some point you probably also want to look at the concrete subclass 
> Logger in the core module: 
> https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java
[https://avatars1.githubusercontent.com/u/47359?v=3=400]

apache/logging-log4j2
github.com
logging-log4j2 - Mirror of Apache Logging Log4J2


>
> Hope this helps to get you