Re: looking for source
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=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 >>&g
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 > > > 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
Re: looking for source
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 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: >>> >&
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", ); >>> >>> >>> 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: >>> >>> >>&
Re: looking for source
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 <nic...@msn.com> 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 <remko.po...@gmail.com> > 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 <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> >> 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. >>> >
Re: looking for source
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 <remko.po...@gmail.com> 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 <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> > 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", ); >>> >>> >>> What's the expected behavior? Meaning, what is the logging framework going >>> to do with the message and the exception? I know the m
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 <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> > 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", ); >>> >>> >>> 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 >>> { >
Re: looking for source
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> 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", ); >> >> >> 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 >> >> >> S
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", ); >> >> >> 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 <remko.po...@gmail.com> >> Sent: Frid
Re: looking for source
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", ); > > > 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 <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=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 > > 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:
Re: looking for source
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 <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 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 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. 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
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 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 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). Enjoy! Remko Sent from my iPhone > On 4 Nov 2016, at 23:29, Nicholas Duanewrote: > > 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
Re: looking for source
Hi, The code is available in Github and you can clone it: https://github.com/apache/logging-log4j2/blob/f3e876a0fefd5d77c6f278b073bfa15df7971c44/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java On Fri, Nov 4, 2016 at 2:32 PM, Matt Sickerwrote: > https://git-wip-us.apache.org/repos/asf?p=logging-log4j2. > git;a=blob;f=log4j-api/src/main/java/org/apache/logging/ > log4j/spi/AbstractLogger.java;h=84ce56791fe375d191a23155a682e9 > c149da6d01;hb=refs/heads/master#l732 > > There's a starting point. > > On 4 November 2016 at 09:29, Nicholas Duane 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 > > > > > > -- > Matt Sicker >