我在SLF4J中有这个日志语句(在它下面有Logback):
logger.info("{} has {} depots, {00} vehicles and {} customers with a search space of {}.", ...);
我得到了这个输出:
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.
但是我想要这个输出,它会增加额外的空间填充/缩进:
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.
这可以用SLF4J吗?
答案 0 :(得分:3)
似乎没有。你应该对每个必须带有额外空格的参数使用String.format(...)。像这样的东西
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");