logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1002) PatternLayout is missing a new line for Exceptions with the short option
Date Fri, 01 May 2015 16:11:06 GMT

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

Gary Gregory commented on LOG4J2-1002:
--------------------------------------

This is a partial fix:

{noformat}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
index a651ae6..d198a02 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java
@@ -147,7 +147,7 @@
             final int limit = options.minLines(array.length) - 1;
             for (int i = 0; i <= limit; ++i) {
                 sb.append(array[i]);
-                if (i < limit) {
+                if (i <= limit) {
                     sb.append(options.getSeparator());
                 }
             }
{noformat}

But this causes the tag lib tests to fail:

{noformat}
Failed tests:
  CatchingTagTest.testDoEndTag:77->verify:107 Incorrect message. expected:<...ion: This
is a test.[]> but was:<...ion: This is a test.[
]>
  CatchingTagTest.testDoEndTagLevelObject:95->verify:107 Incorrect message. expected:<...is
is the last test.[]> but was:<...is is the last test.[
]>
  CatchingTagTest.testDoEndTagLevelString:86->verify:107 Incorrect message. expected:<...his
is another test.[]> but was:<...his is another test.[
]>
  LoggingMessageTagSupportTest.testDoEndTagMessageMarkerException:247->verify:306 Incorrect
message. expected:<...This is another test[]> but was:<...This is another test[
]>
  LoggingMessageTagSupportTest.testDoEndTagMessageNoMarkerException:233->verify:306 Incorrect
message. expected:<...tion: This is a test[]> but was:<...tion: This is a test[
]>
  LoggingMessageTagSupportTest.testDoEndTagObjectMarkerException:292->verify:306 Incorrect
message. expected:<...This is another test[]> but was:<...This is another test[
]>
  LoggingMessageTagSupportTest.testDoEndTagObjectNoMarkerException:280->verify:306 Incorrect
message. expected:<...tion: This is a test[]> but was:<...tion: This is a test[
]>
  LoggingMessageTagSupportTest.testDoEndTagStringMessageMarkerException:167->verify:306
Incorrect message. expected:<...This is another test[]> but was:<...This is another
test[
]>
  LoggingMessageTagSupportTest.testDoEndTagStringMessageNoMarkerException:155->verify:306
Incorrect message. expected:<...tion: This is a test[]> but was:<...tion: This is
a test[
]>
  LoggingMessageTagSupportTest.testDoEndTagStringWithParametersMarkerAndException:194->verify:306
Incorrect message. expected:<...his is the last test[]> but was:<...his is the last
test[
]>

Tests run: 78, Failures: 10, Errors: 0, Skipped: 0
{noformat}

I wonder if the tests are wrong and should allow the EOL or if the tab lib needs to trim if
things need to be parameterized further.

> PatternLayout is missing a new line for Exceptions with the short option
> ------------------------------------------------------------------------
>
>                 Key: LOG4J2-1002
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1002
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts, Pattern Converters
>    Affects Versions: 2.2
>         Environment: Windows, eclipse
>            Reporter: Robert Schaft
>   Original Estimate: 336h
>  Remaining Estimate: 336h
>
> I am struggeling to get the PatternLayout right when using %throwable, %ex or similar.
> The first problem is, that if the exception is limited by the number of lines (e.g. with
the option {{short}} or providing a number), the converter {{ExtendedThrowablePatternConverter}}
doesn't attach a newline to the end of the stack.
> On the other hand it does attach a newline at the end of the full stack.
> That is why
> {quote}
> {{<PatternLayout pattern="%msg%n%ex" />}}
> {quote}
> produces the expected result for message with and without throwables: there are no empty
lines in the log file and every log message starts in a new line. 
> What about {{%ex\{short\}}}?
> {quote}
> {{<PatternLayout pattern="%msg%n%ex\{short\}" />}}
> {quote}
> This has the problem that messages with throwables do not end with a new line. This produces
all kinds of problems.
> Ok, let's add a newline
> {quote}
> {{<PatternLayout alwaysWriteExceptions="false" pattern="%msg%n%ex\{short\}%n" />}}
> {quote}
> This has the problem that messages _without_ throwables are followed by an empty line.
This is not acceptable on the console.
> So we need something more complicated:
> {quote}
> {{<PatternLayout alwaysWriteExceptions="false" pattern="%msg%replace\{%n%ex\{short\}%n\}\{\[\r\n]+$\}\{\}%n"
/>}}
> {quote}
> Yeah! It works (at least on Windows, Unix, Linux, Mac) and if the undocumented throwable
{{separator}} option is not used. But it's ugly and requires the alwaysWriteExceptions because
the throwable pattern detection does not work any more.
> Short Term solution: Always add a newline to the exception.
> Long Term Solution:
> Add a conversion pattern {{%onThrowable\{pattern1\}\[\{pattern2\}]}} where pattern1 is
appended when there is a throwable attached to the log message and the optional pattern2 is
appended when there is no throwable appended.
> The {{alwaysWriteExceptions="false"}} parameter could be replaced by {{pattern="%onThrowable\{\}"}}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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


Mime
View raw message