t0xa / gelfj

Graylog Extended Log Format (GELF) implementation in Java and log4j appender without any dependencies.
https://github.com/t0xa/gelfj/wiki
Other
186 stars 116 forks source link

Allow Appenders and Handlers to pass a zero length message to network #96

Closed ghost closed 8 years ago

ghost commented 8 years ago

This change allows both Appenders (org.apache.log4j.Appender) and Handlers (java.util.logging.Handler) to send zero length and null messages to a remote destination. Previously both zero length and null messages were pruned out in GelfMessage class.

Though pruning out empty messages makes sense in terms of saving (some) network traffic, it's kind of counterintuitive for several reasons.

To begin with, those who are familiar with other implementations expect to see an empty message to get passed along. E.g. o.a.l.ConsoleAppender, o.a.l.FileAppender, j.u.l.ConsoleHandler, and j.u.l.FileHandler all allow a zero length/null message to be passed on.

Additionally, an Appender/Handler implementation is not supposed to prune out any messages, besides invalid ones which simply can not be passed due to missing information. In this case an empty message is not something that prevents it being sent, as long as other GELF parameters are all right. If additional filtering is needed, that should go in org.apache.log4j.Filter or java.util.logging.Filter implementation respectively.

Finally, there is a use case for sending empty messages as well. Some developer might want to do log.info(thisStringIGotPassed), and should the string be empty, it'd be reasonable to expect an empty log entry appear, instead of receiving an error "Could not send GELF message".

References:

https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Appender.html https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html

https://docs.oracle.com/javase/7/docs/api/java/util/logging/Filter.html https://docs.oracle.com/javase/7/docs/api/java/util/logging/Handler.html

t0xa commented 8 years ago

Hi @samilaine,

I appreciate the effort you put in this pull request. It's a great example of how collaboration should be done!

Thank you.

t0xa commented 8 years ago

Hi @samilaine,

Version 1.1.14 with your pull request released. Thanks again for your help.

Anton

ghost commented 8 years ago

The pleasure was all mine. Thank you for putting Gelfj together.