Moocar / logback-gelf

Logback plugin to send GELF messages to graylog2 server
Apache License 2.0
147 stars 59 forks source link

Feature request: Adding numeric field to a gelf message through logback #30

Closed dklotz closed 10 years ago

dklotz commented 10 years ago

At the moment I don't see any way to (dynamically) add a numeric field (with a number, not with a string value) to a message logged through logback-gelf. This would be great to have, because it would allow us to filter, graph etc. these messages in graylog based on that numeric value (e.g. "only warnings for messages where _size > 500"). The MDC seems to be of no help, because it only takes String values for each key.

Any ideas if this is even remotely possible?

Moocar commented 10 years ago

Cool idea, unfortunately you're right about the MDC. It is a map of String,String.

One potential way around this is to associate an expected type with a field name. That way when we pull the fields out of the MDC, we then find the type associated with that field name, then convert the value in the MDC into that type before saving it to json. The interface might look something like this:

<appender  name="GELF" class="me.moocar.logbackgelf.GelfAppender">
  <additionalField type="number">fooField:_foo_field</additionalField>
</appender>

This seems pretty clear to me, but it wouldn't support the includeFullMDC option. For that, we'd need to do something like

<includeFullMDC>true</includeFullMDC>
<fieldType>_foo_field:number</fieldType>

That one seems a bit more ugly to me. Out of interest, in your case, are you using includeFullMDC or are you specifying specific additionalFields?

dklotz commented 10 years ago

We're using includeFullMDC. Being able to override the type for specific fields (either through the existing additionalField with an an added type parameter or through a new fieldType option or similar) would be a great way to enable this while still staying with the normal logback API in code.

Moocar commented 10 years ago

Feature implemented as part of #31. Enjoy :) (thanks @pktxu)