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

Gary Gregory commented on LOG4J2-1078:
--------------------------------------

The GELF spec (1) says:

{quote}
host string (UTF-8)
the name of the host, source or application that sent this message; MUST be set 
by client library.
{quote}

To me, that means it must be set to "something", not null. Hence the current 
implementation.

Looking at the spec and our source I wonder if we should be calling 
{{quoteAsUTF8()}} instead of {{quoteAsString()}}...

{quote}
refuse to create the layout if null/unset.
{quote}

The layout framework does not let you do that ATM.

Gary

(1) https://www.graylog.org/resources/gelf-2/#gelf

> 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