Great, that explains it.
Thanks, Nick ________________________________ From: Ralph Goers <ralph.go...@dslextreme.com> Sent: Sunday, November 6, 2016 8:14 PM To: Log4J Users List Subject: Re: looking for source Because most people want the exception printed PatternLayout includes the ExtendedThrowableConverter by default as the last parameter unless you specify %noex. The exception is normally not formatted by the Message. Ralph > On Nov 6, 2016, at 4:22 PM, Nicholas Duane <nic...@msn.com> wrote: > > My configuration simply has %msg in the pattern layout to output the message. > However, that seems to be outputting the message along with some serialized > representation of the exception. I was looking at the message pattern > converter at: > > > https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java [https://avatars1.githubusercontent.com/u/47359?v=3&s=400]<https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java> apache/logging-log4j2<https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java> github.com logging-log4j2 - Mirror of Apache Logging Log4J2 > > > which I assume is what formats the string for the %msg pattern. Is that > correct? I don't see in the code where it's getting the exception info, but > I guess it might already be in the Message object. > > > Thanks, > > Nick > > ________________________________ > From: Ralph Goers <ralph.go...@dslextreme.com> > Sent: Sunday, November 6, 2016 1:38 AM > To: Log4J Users List > Subject: Re: looking for source > > 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 <nic...@msn.com> 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 <remko.po...@gmail.com <mailto:remko.po...@gmail.com>> >> 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 <nic...@msn.com> 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 <remko.po...@gmail.com> >>> 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 <nic...@msn.com> 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", <some throwable>); >>>> >>>> >>>> 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: >>>> >>>> >>>> <?xml version="1.0" encoding="UTF-8"?> >>>> <Configuration status="WARN"> >>>> <Appenders> >>>> <Console name="Console" > >>>> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} >>>> \ >>>> - %msg%n"/> >>>> </Console> >>>> </Appenders> >>>> <Loggers> >>>> <Root level="info"> >>>> <AppenderRef ref="Console"/> >>>> </Root> >>>> </Loggers> >>>> </Configuration> >>>> >>>> >>>> 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 <remko.po...@gmail.com> >>>> 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&s=400]<https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java> >> >> apache/logging-log4j2<https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java> >> github.com >> logging-log4j2 - Mirror of Apache Logging Log4J2 >> >> >>> [https://avatars1.githubusercontent.com/u/47359?v=3&s=400]<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&s=400]%3Chttps://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java%3E> >>> >>> apache/logging-log4j2<https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java >>> >>> <https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java>> >>> github.com <http://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&s=400]<https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java> >>> >>> apache/logging-log4j2<https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java> >>> github.com >>> logging-log4j2 - Mirror of Apache Logging Log4J2 >>> >>> >>>> >>>> Hope this helps to get you started. >>>> >>>> It may be easier to use an IDE and check out the whole project >>>> (https://logging.apache.org/log4j/2.x/source-repository.html). >> Log4j – Source Repository - Apache Log4j >> 2<https://logging.apache.org/log4j/2.x/source-repository.html> >> logging.apache.org >> Access from Behind a Firewall. Refer to the documentation of the SCM used >> for more information about access behind a firewall. >> >> >>> Log4j - Source Repository - Apache Log4j >>> 2<https://logging.apache.org/log4j/2.x/source-repository.html> >> Log4j – Source Repository - Apache Log4j >> 2<https://logging.apache.org/log4j/2.x/source-repository.html> >> logging.apache.org >> Access from Behind a Firewall. Refer to the documentation of the SCM used >> for more information about access behind a firewall. >> >> >>> logging.apache.org >>> Access from Behind a Firewall. Refer to the documentation of the SCM used >>> for more information about access behind a firewall. >>> >>> >>>> Log4j - Source Repository - Apache Log4j >>>> 2<https://logging.apache.org/log4j/2.x/source-repository.html >>>> <https://logging.apache.org/log4j/2.x/source-repository.html>> >> Log4j – Source Repository - Apache Log4j >> 2<https://logging.apache.org/log4j/2.x/source-repository.html >> <https://logging.apache.org/log4j/2.x/source-repository.html>> >> logging.apache.org <http://logging.apache.org/> >> Access from Behind a Firewall. Refer to the documentation of the SCM used >> for more information about access behind a firewall. >> >> >>> Log4j - Source Repository - Apache Log4j >>> 2<https://logging.apache.org/log4j/2.x/source-repository.html >>> <https://logging.apache.org/log4j/2.x/source-repository.html>> >> Log4j – Source Repository - Apache Log4j >> 2<https://logging.apache.org/log4j/2.x/source-repository.html >> <https://logging.apache.org/log4j/2.x/source-repository.html>> >> logging.apache.org <http://logging.apache.org/> >> Access from Behind a Firewall. Refer to the documentation of the SCM used >> for more information about access behind a firewall. >> >> >>> logging.apache.org <http://logging.apache.org/> >>> Access from Behind a Firewall. Refer to the documentation of the SCM used >>> for more information about access behind a firewall. >>> >>> >>>> logging.apache.org <http://logging.apache.org/> >>>> Access from Behind a Firewall. Refer to the documentation of the SCM used >>>> for more information about access behind a firewall. >>>> >>>> >>>> >>>> Enjoy! >>>> Remko >>>> >>>> Sent from my iPhone >>>> >>>>> On 4 Nov 2016, at 23:29, Nicholas Duane <nic...@msn.com> wrote: >>>>> >>>>> I'm not that familiar with java and java conventions, package names, etc. >>>>> I'm trying to find the source for log4j2's implementation of >>>>> logger.error(String, Throwable);. Can someone point me to that? I was >>>>> looking around here: >>>>> >>>>> >>>>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=tree;hb=refs/heads/master >>>>> >>>>> >>>>> But couldn't seem to find what I was looking for. >>>>> >>>>> >>>>> Thanks, >>>>> >>>>> Nick >>> >>> --------------------------------------------------------------------- >>> 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 > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org