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

Mikael Ståldal commented on LOG4J2-1078:
----------------------------------------

I would not say that I am a GELF _expert_, even though I use it regularly.

The GELF spec says: 

{code}
short_message string (UTF-8)

a short descriptive message; MUST be set by client library.
{code}

This mean that we cannot leave it out, and we cannot set it to JSON {{null}}. 
It must be present and set to some string. The GELF spec does not provide any 
explicit way to not have a message.

I guess that in Log4j, {{event.getMessage().getFormattedMessage() == null}} is 
uncommon and not expected most of the time, but it is obviously possible and we 
have to deal with it somehow.

So let's leave it as {{""}}, to emphasize the fact that it is an odd case.

(I recently encountered a {{null}} log message from a library I use, and I have 
ensured that there exists a bug report to fix that, since I think that's an 
improper use of Log4j, or SLF4J as the library is using.)

> GelfLayout throws exception if some log event fields are null
> -------------------------------------------------------------
>
>                 Key: LOG4J2-1078
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1078
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.3
>            Reporter: Mikael Ståldal
>             Fix For: 2.4
>
>
> When log message is null:
> {code}
> 2015-07-08 11:07:41,761 ERROR An exception occurred processing Appender 
> Console java.lang.NullPointerException
>       at 
> com.fasterxml.jackson.core.io.JsonStringEncoder.quoteAsString(JsonStringEncoder.java:106)
>       at 
> org.apache.logging.log4j.core.layout.GelfLayout.toSerializable(GelfLayout.java:217)
>       at 
> org.apache.logging.log4j.core.layout.GelfLayout.toByteArray(GelfLayout.java:184)
>       at 
> org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:108)
>       at 
> org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)
>       at 
> org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)
>       at 
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)
>       at 
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)
>       at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
>       at 
> org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:727)
>       at 
> org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:716)
> {code}



--
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