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?
Native implementation of slf4j is logback, thus using both as logger framework implies zero memory and computational overhead.
The SLF4J or the Simple Logging Facade for Java is an abstraction layer for various Java logging frameworks, like Log4j 2 or Logback. This allows for plugging different logging frameworks at deployment time without the need for code changes.
Bindings are basically implementations of a particular SLF4J class meant to be extended to plug in a specific logging framework. By design, SLF4J will only bind with one logging framework at a time. Consequently, if more than one binding is present on the classpath, it will emit a warning.
If SLF4J cannot find a binding on the class path it will emit a single warning message and default to no-operation implementation. SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With