[logback-dev] [JIRA] Commented: (LBCLASSIC-232) %n is necessary to separate real message from exception stack trace

Michael Osipov (JIRA) noreply-jira at qos.ch
Wed Nov 10 10:06:51 CET 2010


    [ http://jira.qos.ch/browse/LBCLASSIC-232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11891#action_11891 ] 

Michael Osipov commented on LBCLASSIC-232:
------------------------------------------

Ceki,

yes, I am absolutely aware. Probably I made the point not clear enough.
Consider this pattern:
%d %level - %msg%n
I pass to a slf4j => info("this is {} news", "bad", e);

in this case logback produces:
2010-11-10 10:01:00 INFO - this is bad news
com.some.Exception...
2010-11-10 10:02... news log event

and now the a slightly modified pattern:
%d %level - %msg
I pass to a slf4j => info("this is {} news", "bad", e);

in this case logback produces:
2010-11-10 10:01:00 INFO - this is bad newscom.some.Exception... 2010-11-10 10:02... news log event

All of a sudden there is no line feed between the string message in the exception although the msg behavior has not been modified. All I did was to seperate whole log events with a lne feed.
I deduce from this that somehow the %n is take into account when a line feed is appended between the msg subpart and the exception string.

If you need an example, I will provide one.

> %n is necessary to separate real message from exception stack trace
> -------------------------------------------------------------------
>
>                 Key: LBCLASSIC-232
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-232
>             Project: logback-classic
>          Issue Type: Bug
>          Components: layout
>    Affects Versions: 0.9.26
>            Reporter: Michael Osipov
>            Assignee: Logback dev list
>
> I started using the SMTPAppender and defined this pattern layout:
> <Pattern>Zeitstempel: %date%(%n)Kontext: %contextName%(%n)Angeforderte URI: %X{req.requestURI}%(%n)QueryString: %X{req.queryString}%(%n)Nachricht: %msg</Pattern>
> I do receive single log messages only so I don't need a %n at the end. Unfortunately, my log messages are messed up.
> Instead of:
> Nachricht: <msg>
> <ex>
> as the default log layout, I get:
> Nachricht: <msg><ex>
> I added a %n and it solved the problem. I was able to reproduce this with the FileAppender but this behavior make no sense. The exception is part of the message and should always include a \n internally unless a %ex is exlicitly defined. The last %n includes two line feed at once.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list