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, newlines and Exceptions
Date Fri, 01 May 2015 07:34:06 GMT

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

Gary Gregory commented on LOG4J2-1002:

Why isn't the solution to make sure we have an EOL after all stack traces, long or short?

> PatternLayout, newlines and Exceptions
> --------------------------------------
>                 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

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

View raw message