[slf4j-dev] Support for structured logging in SLF4J 2.0

João Cabrita joao.r.cabrita at gmail.com
Sun Feb 19 17:10:59 CET 2017


Hi,

I've been looking through the issue tracker and I've found that there is a
2.0 release planned which would include some API changes.

I've been working a lot with Graylog lately, and am of the opinion that
SLF4J's API doesn't really cover that use case in a way that feels natural,
so I'd like to know if such structured logging approaches could be covered
in the new release.

For example, besides the regular message, Graylog supports adding custom
fields to logs.
Although this is supported by SLF4J through MDC, sometimes you only need
the one log statement with a given field, in which case MDC is inconvenient
because you'd need to:

1. Add the value to the MDC
2. Log
3. Remove the value

One way I can think of doing this is replacing the formatted approach, i.e.:

  log.info("This is a message with {}", "some value");

with

  log.info("This is a message", singletonMap("value", "some value"));

I think this fits the structured logging model more naturally but is also
suited for logging to file/stdout if you add a fields marker to formatters
(similar to the one in MDC).

Any opinions on this?

João Cabrita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-dev/attachments/20170219/a299c92c/attachment.html>


More information about the slf4j-dev mailing list