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?

有帮助吗?

解决方案

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");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top