Use decimalformat in slf4j or logback to pad or ident numbers so they align right

java, logback, logging, slf4j

Solution

It seems no. You should use String.format(...) for each argument which has to be with extra spaces. Something like this

logger.info("{} has {} depots, {} vehicles and {} customers with a search space of {}.", String.format("%-9s", "A-n62-k8"), "1", String.format("%-2s", "8"), "61", "10^108");

Problem

I have this log statement in SLF4J (with Logback below it): ``` logger.info("{} has {} depots, {00} vehicles and {} customers with a search space of {}.", ...); ``` And I get this output: ``` A-n62-k8 has 1 depots, 8 vehicles and 61 customers with a search space of 10^108. A-n63-k10 has 1 depots, 10 vehicles and 62 customers with a search space of 10^111. ``` But I want this output, which add extra space padding/indentation: ``` A-n62-k8 has 1 depots, 8 vehicles and 61 customers with a search space of 10^108. A-n63-k10 has 1 depots, 10 vehicles and 62 customers with a search space of 10^111. ``` Is this possible with SLF4J?

Original source