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

Gary Gregory commented on LOG4J2-908:
-------------------------------------

WRT commas and documents. 

Right now you can do a couple of things. You can have an appender and layout 
create a valid JSON document assuming Log4j shutsdown cleanly. This means 
you'll get a JSON document that is an array of log events. This usually makes 
most sense when you log to a file. This is the same concept as with the XML 
layout when you need to close the root element.

Otherwise, you can create a stream of log events by setting complete to false, 
which will not emit the [ and ]. If you also set compact to false, you'll get 
no formatting. 

Depending on how your JSON parser works, this can work or not. Can your parser 
not know when an object end? Or does your parser blow up if it sees an 
incomplete object? I would imagine that if a parser is reading from stream as 
opposes to from a string, it would block until more bytes are available.

An alternative would be to propose a new property like "eventPostfix" which you 
can set to end of line (%n perhaps if we use the pattern layout format). So if 
you use eventPostifx="%n", compact="true", and complete="false", you'd get one 
log event per line, but not as a complete JSON doc.

Thoughts?

> JSONLayout doesn't add a comma between log events
> -------------------------------------------------
>
>                 Key: LOG4J2-908
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-908
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.1
>            Reporter: Konstantinos Liakos
>            Assignee: Gary Gregory
>             Fix For: 2.5.1
>
>
> JSONLayout doesn't output a comma (,) between the log events. This makes it 
> quite difficult to read and deserialize the log files.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to