[slf4j-user] When more parameters than placeholders, extra parameters are not logged

Ceki Gulcu ceki at qos.ch
Sun Feb 2 15:46:56 UTC 2025


Hi all,

For your information, in addition to being efficient and clean, SLF4J's 
fluent API also allows setting the message via a supplier (closure).


See

https://www.slf4j.org/manual.html#fluent

and also

https://www.slf4j.org/apidocs/org/slf4j/spi/LoggingEventBuilder.html

On 02/02/2025 11:35, Joachim Durchholz via slf4j-user wrote:
> An additional thought:
> 
> Modern JVMs are pretty efficient at building closures.
> Log4j2 (not the old log4j version 1) is an alternative where you can 
> replace
> 
>    logger.debug("foo is: " + foo)
> 
> with
> 
>    logger.debug(() -> "foo is: " + foo)
> 
> This has the same avoid-constructing-strings logic as
> 
>    logger.debug("foo is: {}", foo)
> 
> but you don't need to refactor anything.
> 
> The downside is that forgetting to create the closure will make logging 
> slow, so in the end, you'll likely fall back to the same make-sure- 
> everything-is-mass-refactored approach as before, so the overall 
> advantage isn't big.
> However, you'll get low-hanging fruits faster, at the expense of having 
> to try out a different logging framework.
> 
> Which means I won't recommend anything, I'm just presenting more choices 
> in the hopes that one of them matches your situation better.
> 
> Regards,
> Jo
> _______________________________________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> https://mailman.qos.ch/cgi-bin/mailman/listinfo/slf4j-user

-- 
Ceki Gülcü

Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch



More information about the slf4j-user mailing list