logback-gelf icon indicating copy to clipboard operation
logback-gelf copied to clipboard

GelfMessage should fail on host = "", shortmessage=""

Open ipavkovic opened this issue 3 years ago • 3 comments

Describe the bug We have a logging with a short message "" (coming from the root cause NullPointerException)

GelfMessage checks for null but not empty message. Our Graylog server silently skips a message with short_message = "" even if full message is filled properly

        this.host = Objects.requireNonNull(host, "host must not be null");
        this.shortMessage = Objects.requireNonNull(shortMessage, "shortMessage must not be null");

should be changed to something like

        this.host = requireNotEmpty(host, "host must not be empty");
        this.shortMessage = requireNotEmpty(shortMessage, "shortMessage must not be empty");
[...]
       private static void requireNotEmpty(String value, String message) {
         if (value == null || value.trim().isEmpty()) {
           throw new IllegalStateException(message);
         }
       }

insert test code here


ipavkovic avatar Feb 21 '22 12:02 ipavkovic

Related: https://github.com/Graylog2/graylog2-server/issues/5171

osiegmar avatar Feb 21 '22 13:02 osiegmar

Which version of graylog-server do you use?

osiegmar avatar Feb 21 '22 13:02 osiegmar

Graylog2/graylog2-server#5171

Graylog 3.3.16+f766a24

ipavkovic avatar Feb 21 '22 15:02 ipavkovic

According to GelfCodec.java, Graylog requires a short_message that "is not blank" (by using Apache Commons Lang3 StringUtils). The definition of blank by org.apache.commons.lang3.StringUtils#isBlank:

Checks if a CharSequence is empty (""), null or whitespace only. Whitespace is defined by Character.isWhitespace(char).

So this will be changed in the next release of this library.

osiegmar avatar Dec 23 '22 19:12 osiegmar