M
M
mitaichik2017-10-20 15:20:41
Java
mitaichik, 2017-10-20 15:20:41

Logback: how to format a message?

Hello! I use slf4g + Logback.
There is a code that displays the log:
logger.info("{} {} {}", arg1, arg2, arg3)
I want it to be displayed as if in columns:

2017-10-20 15:18:58 INFO  test.TestApp - 0        aaaaaa        2
2017-10-20 15:18:58 INFO  test.TestApp - 123      ss            2
2017-10-20 15:18:58 INFO  test.TestApp - 99       dddddddd      2

Can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-10-20
@mitaichik

slf4j has a very simple formatter that only knows how to substitute values ​​into anchors in line order. If you need complex formatting, then you will have to use a more functional, but also slower Java formatter:

logger.info(String.format("%-20s %-20s %-2d", arg1, arg2, arg3));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question