Log4j 2
  1. Log4j 2
  2. LOG4J2-374

Add more options to PatternLayout to display more detailed information about a Throwable

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-beta9
    • Component/s: Layouts
    • Labels:
      None

      Description

      That would be useful if we got more details about the method which threw the exception. There is a "short" form, which contains these information, but there can be some cases, when we need them separately.

      For example we would write something like this:

      %throwable{className}.%throwable{methodName}:%throwable{lineNumber} %throwable{message}
      

      And we would get this:

      foo.bar.ClassName.main:14 java.lang.ArithmeticException: / by zero
      

      I think we should only modify the ThrowablePatternConverter and ThrowableFormatOptions classes and the documentation. What do you think about it?

      1. LOG4J2-374.patch
        11 kB
        Tibor Benke
      2. LOG4J2-374_v2.patch
        13 kB
        Tibor Benke

        Activity

        Tibor Benke made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Tibor Benke added a comment -

        It has been verified and complete.

        Show
        Tibor Benke added a comment - It has been verified and complete.
        Hide
        Tibor Benke added a comment -

        It's my pleasure

        I verified the modifications.

        Show
        Tibor Benke added a comment - It's my pleasure I verified the modifications.
        Gary Gregory made changes -
        Fix Version/s 2.0-beta9 [ 12324756 ]
        Affects Version/s 2.0-beta9 [ 12324756 ]
        Gary Gregory made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Gary Gregory added a comment - - edited

        Patch applied with a few changes.

        Thank you Tibor!

        commit -m "[LOG4J2-374] Add more options to PatternLayout to display more detailed information about a Throwable." C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java C:/vcs/svn/apache/log4j2/trunk/src/changes/changes.xml C:/vcs/svn/apache/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableFormatOptions.java
            Sending        C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableFormatOptions.java
            Sending        C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
            Adding         C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java
            Sending        C:/vcs/svn/apache/log4j2/trunk/src/changes/changes.xml
            Sending        C:/vcs/svn/apache/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm
            Transmitting file data ...
            Committed revision 1519707.
        
        Show
        Gary Gregory added a comment - - edited Patch applied with a few changes. Thank you Tibor! commit -m "[LOG4J2-374] Add more options to PatternLayout to display more detailed information about a Throwable." C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java C:/vcs/svn/apache/log4j2/trunk/src/changes/changes.xml C:/vcs/svn/apache/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableFormatOptions.java Sending C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableFormatOptions.java Sending C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java Adding C:/vcs/svn/apache/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverterTest.java Sending C:/vcs/svn/apache/log4j2/trunk/src/changes/changes.xml Sending C:/vcs/svn/apache/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm Transmitting file data ... Committed revision 1519707.
        Tibor Benke made changes -
        Attachment LOG4J2-374_v2.patch [ 12601037 ]
        Hide
        Tibor Benke added a comment -

        You are right. I'm not good in giving names

        Btw I'm going to attach a new patch. I edited the code, so now this feature is part of the ThrowablePatternConverter class.

        Show
        Tibor Benke added a comment - You are right. I'm not good in giving names Btw I'm going to attach a new patch. I edited the code, so now this feature is part of the ThrowablePatternConverter class.
        Hide
        Gary Gregory added a comment - - edited

        Any thoughts from others?

        I'm not sure this should be a separate class and %name.

        It could also be:

        %throwable{short.className}
        %throwable{short.methodName} 
        

        and so on.

        If it is a separate class, I would call it %ShortThrowable as opposed to the proposed %csThrowable which is too cryptic IMO.

        Thoughts?

        Show
        Gary Gregory added a comment - - edited Any thoughts from others? I'm not sure this should be a separate class and %name. It could also be: %throwable{short.className} %throwable{short.methodName} and so on. If it is a separate class, I would call it %ShortThrowable as opposed to the proposed %csThrowable which is too cryptic IMO. Thoughts?
        Tibor Benke made changes -
        Attachment LOG4J2-374.patch [ 12600395 ]
        Hide
        Tibor Benke added a comment -

        Review ready patch

        Show
        Tibor Benke added a comment - Review ready patch
        Hide
        Tibor Benke added a comment -

        I thought about it and I think we should use another pattern name than %throwable in this case, because this improvement would imply the use of %throwable

        {short}

        form, so it would be specious. Maybe the DetailedShortThrowablePatternConverter or CustomShortThrowablePatternConverter would be more expressive, so we could use the %dsThrowable or %csThrowable names.

        Show
        Tibor Benke added a comment - I thought about it and I think we should use another pattern name than %throwable in this case, because this improvement would imply the use of %throwable {short} form, so it would be specious. Maybe the DetailedShortThrowablePatternConverter or CustomShortThrowablePatternConverter would be more expressive, so we could use the %dsThrowable or %csThrowable names.
        Hide
        Gary Gregory added a comment - - edited

        You might as well throw in %throwable{fileName} while you are in there

        Patches welcome.

        Show
        Gary Gregory added a comment - - edited You might as well throw in %throwable{fileName } while you are in there Patches welcome.
        Tibor Benke made changes -
        Field Original Value New Value
        Description That would be useful if we got more details about the method which threw the exception. There is a "short" form, which contains these information, but there can be some cases, when we need them separately.

        For example we would write something like this:

        %throwable{className}.%throwable{methodName}:%throwable{lineNumber} %throwable{message}

        And we would get this:

        foo.bar.ClassName.main:14 java.lang.ArithmeticException: / by zero

        I think we should only modify the ThrowablePatternConverter and ThrowableFormatOptions classes and the documentation. What do you think about it?
        That would be useful if we got more details about the method which threw the exception. There is a "short" form, which contains these information, but there can be some cases, when we need them separately.

        For example we would write something like this:

        {noformat}
        %throwable{className}.%throwable{methodName}:%throwable{lineNumber} %throwable{message}
        {noformat}

        And we would get this:

        {noformat}
        foo.bar.ClassName.main:14 java.lang.ArithmeticException: / by zero
        {noformat}

        I think we should only modify the ThrowablePatternConverter and ThrowableFormatOptions classes and the documentation. What do you think about it?
        Tibor Benke created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Tibor Benke
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development