You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Jason Winnebeck (JIRA)" <ji...@apache.org> on 2014/02/19 16:12:21 UTC

[jira] [Comment Edited] (LOG4J2-504) Problems with message field when using MultiformatMessage in JSONLayout

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

Jason Winnebeck edited comment on LOG4J2-504 at 2/19/14 3:10 PM:
-----------------------------------------------------------------

I see this problem too, I wanted to use MapMessage here so I could get a parsable log, but I get this: "message":"{"action":"getVersion", "duration":"0", "result":"success"}"

The problem is in JSONLayout line 188 and 194 the quote is appended whether or not "jsonSupported" is true. Also, the other comment about MapMessage not escaping JSON characters is also valid, although fortunately I can ensure that the values I output will not have these characters in them.

The workaround is to write your own layout... Or in my case for this specific task I'll probably just have to not use log4j for these messages and output a separate file because I need the output to be parseable.

EDIT: in my case the workaround I decided upon finally was to do a log.trace with the exact JSON output I wanted and route that logger to an appender using simply a %msg%n pattern layout. The log.isTraceEnabled() allows me to skip the JSON generation when possible.


was (Author: gillius):
I see this problem too, I wanted to use MapMessage here so I could get a parsable log, but I get this: "message":"{"action":"getVersion", "duration":"0", "result":"success"}"

The problem is in JSONLayout line 188 and 194 the quote is appended whether or not "jsonSupported" is true. Also, the other comment about MapMessage not escaping JSON characters is also valid, although fortunately I can ensure that the values I output will not have these characters in them.

The workaround is to write your own layout... Or in my case for this specific task I'll probably just have to not use log4j for these messages and output a separate file because I need the output to be parseable.

> Problems with message field when using MultiformatMessage in JSONLayout
> -----------------------------------------------------------------------
>
>                 Key: LOG4J2-504
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-504
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.0-beta9
>            Reporter: Michael Friedmann
>         Attachments: log4j2Test.tar.gz
>
>
> When using MultiformatMessage (e.g. MapMessage) in the JSONLayout, the "message" is properly JSON formatted.  However, it is surrounded by quotes, rendering the overall JSON invalid.  When the quotes are removed, everything works fine.
> Additionally, the individual properties of the MapMessage may already contain JSON formatted values.  These are currently surrounded by quotes as well, again rendering the overall JSON invalid.  Note that for properties whose values are plain strings, however, these need to be JSON escaped.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

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