[slf4j-user] FYI - structured logging wrapper for SLF4J

Joachim Durchholz jo at durchholz.org
Tue Oct 1 21:50:16 CEST 2019


Am 01.10.19 um 21:08 schrieb Jordan Zimmerman:
>> JSON is a proper superset of what you'd put into a structured log 
>> message, so I am still not so sure about the added value of Maple.
> 
> I'm not sure what you mean. Can you give more details?

What you're doing is

MapleLogger<LoggingSchema> logger = Logging.get...
...
logger.info(s -> s.fluent().call().chain())

This creates tight coupling between logging and the fluent API for 
generating a structured message.

I think it would be less coupling if this were:

Logger logger = LoggerFactory.getLogger(...)
...
logger.info(() -> S.fluent().call().chain())

because then you can use that S.fluent().call().chain() code in other 
contexts - inside a debugger for temporarily printing data, for example, 
or just to see how the log message starts, or to reuse the structured 
message generation framework in other contexts.
In other words: The coupling becomes looser.

I am well aware that changing the overall architecture in such a way is 
not something to be considered lightly.
And I am not sure that SLF4J can handle lambdas well enough to make this 
feasible, so maybe this is not possible (OTOH since I have the luxury of 
not needing an immediate situation, I can say that I'd prefer SLF4J 
adding that support before having a library that does this...) (OT3H I 
may be moving towards log4j2 in the next months anyway, which has most 
of the nice things in SLF4J anyway and does offer lambda support 
already... though I haven't taken enough of a look to be sure that I 
should really take that step)

Regards,
Jo


More information about the slf4j-user mailing list