문제

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