wr0ngway / log4r-gelf

A Log4r appender for logging to a gelf sink, e.g. the graylog2 server
MIT License
17 stars 5 forks source link

intuitive message setting #4

Closed teubanks closed 10 years ago

teubanks commented 12 years ago

Instead of allowing the message to get set to the full_message, we're setting message to the message that was logged. This fixes the problem where we have trace turned on, which sets the message to what the full message is.

This will make things easier to read/understand in cases where Graylog2 is used to display log messages.

wr0ngway commented 12 years ago

Thanks for the contribution! How is setting message different from short_message? The contents always seem to be the same in the tests. Does graylog2 treat them differently?

teubanks commented 12 years ago

The problem is that if I don't set message to short_message as the logs are coming into logstash, logstash will use the full_message as the message (https://github.com/logstash/logstash/blob/master/lib/logstash/inputs/gelf.rb#L103).

It seems like it'd be a better user experience if the message was set to the actual message that was logged, not the short message and definitely not the full message.

wr0ngway commented 12 years ago

I think this change would be better made in gelf input for logstash rather than this gem. The gelf spec only mentions short_message: https://github.com/Graylog2/graylog2-docs/wiki/GELF

One could set "_message" as a custom field, but that could be confusing with short_message. If you wanted to set short_message to logevent.data.message, log4r (and this gem) provides for that by allowing you to configure a formatter for the message:

- type: GelfOutputter
  ...
  formatter   :
    pattern     : '#{event.data.respond_to?(:message) ? event.data.message : event.data}'
    type        : PatternFormatter