logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1838) Add support for appending common suffix to each line of throwable stack trace
Date Mon, 06 Mar 2017 13:56:32 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15897343#comment-15897343

ASF GitHub Bot commented on LOG4J2-1838:

Github user xnslong commented on the issue:

    @jvz Thanks for your opinion. 
    You asked `why it is not implemented by creating another PatternConverter`. We know there
already exists 3 `PatternConverter`s that can render the throwable stack trace, respectively
handling the `%Ex`, `%xEx` and `%rEx` patterns. These `PatternConverter`s will render the
stack trace with a lot of controls, such as controlling the line number, ignoring certain
packages, limiting the columns, adding package and jar information, and many more. If this
PR is implemented by creating another `PatternConverter` just like what the previously mentioned
`PatternConverter`s do (suppose the corresponding handled pattern is `%sEx`), then if a user
wish to use the suffix functionality provided by this code, he must use the `%sEx` pattern
instead of pattern `%xEx` or `%rEx`, thus he cannot enjoy the benefit provided by the existing
`PatternConverter`s. This will be a little troublesome. So I finally choose to extend the
function of the existing `PatternConverter`s by adding certain option support. 
    Another thing you said is that something here looks like the `VariablesNotEmptyPatternConverter`.
I checked the code, they really resemble each other very much, and this is just what I wish.
My primary thought is to add MDC information as the suffix to each line of the entire stack
trace. But then I found it is too limited. So I made the option to be configurable with existing
patterns, and this is just what the `VariablesNotEmptyPatternConverter` converter wants. 

> Add support for appending common suffix to each line of throwable stack trace
> -----------------------------------------------------------------------------
>                 Key: LOG4J2-1838
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1838
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Pattern Converters
>    Affects Versions: 2.8.1
>            Reporter: Zilong Song
>              Labels: features
>             Fix For: 2.8.2
> Add support for appending common suffix to each line of throwable stack trace. The suffix
can be configured by patterns just like patterns used elsewhere. 
> For example, pattern {{%xEx&#123;suffix(- %mdc&#123;key&#125;)&#125;}}
will append a string generated by pattern {{-&#32;}}  and {{%mdc&#123;key&#125;}}.
> But patterns that handles throwable will be automatically ignored, because they will
make the rendered result confusing. So pattern {{%xEx&#123;suffix(- %rEx%mdc&#123;key&#125;)&#125;}}
has the same effect with {{%xEx&#123;suffix(- %mdc&#123;key&#125;)&#125;}},
as if the nested {{%rEx}} pattern has never appeared.
> Following is an example of the with such suffix: 
> {code:title=stack trace, with pattern "%xEx&#123;suffix(- %mdc&#123;key&#125;)&#125;"
and MDC(key)="test mdc suffix"|borderStyle=solid}
> java.lang.IllegalArgumentException: IllegalArgument - test mdc suffix
> 	at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverterTest.testSuffixFromNormalPattern(ExtendedThrowablePatternConverterTest.java:48)
[test-classes/:?] - test mdc suffix
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91] - test
mdc suffix
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[?:1.8.0_91] - test mdc suffix
> 	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91] - test mdc suffix
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:?]
- test mdc suffix
> Caused by: java.lang.NullPointerException: null pointer - test mdc suffix
> 	at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverterTest.testSuffixFromNormalPattern(ExtendedThrowablePatternConverterTest.java:47)
~[test-classes/:?] - test mdc suffix
> 	... 27 more - test mdc suffix
> }}
> {code}

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message