[slf4j-dev] More variable parameters than placeholders, some parameters not logged

slf4j developers list slf4j-dev at qos.ch
Sun Jan 26 16:32:22 UTC 2025


Hello Russ,

On 24/01/2025 19:46, slf4j developers list via slf4j-dev wrote:

Thank you for your comments.

> With this method or any similar method,
>      public void info(String format, Object... arguments) {
>          if (isInfoEnabled()) {
>              handleArgArrayCall(Level.INFO, null, format, arguments);
>          }
>      }
> If the number of objects in 'arguments' is more than the number of 
> placeholders, {}, the extra argument objects are not logged.  Is there a 
> reason for that?

The reason is that catering for this eventuality would be relatively 
complicated. More importantly, I think that it is not SLF4J's 
responsibility to fix every possible error that could be made by the 
programmer.

> For example
>    public void setTemperature(Integer temperature) {
>      oldT = t;
>      t = temperature;
>    //Sent three parameters log with two placeholders
>    //Output "Temperature set to 90. Old value was null."  The word extra 
> is not printed
>      logger.info("Temperature set to {}. Old value was {}.", t, oldT, 
> "extra");
>      if(temperature.intValue() > 50) {
>        logger.info("Temperature has risen above 50 degrees.");
>      }
>    }

The fluent API allows adding key value pairs which should avoid this 
pitfall.

Best regards,

-- 
Ceki Gülcü

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



More information about the slf4j-dev mailing list