I'm wondering if it is possible in Log4j 2.0 library to pad more conversion specifiers concatenated together.
For example, this pattern
%d{HH:mm:ss,SSS} %-5p [%-10t] %-22c - %m%n
produces something like
12.25.34,788 INFO [SomeThread] my.path.to.Class - First logged message
12.25.34,789 FATAL [Thread2 ] other.path.SecondClass - Second logged message
12.25.34.790 WARN [Scheduler ] my.other.path.Class - Another message
Now imagine I want to pad not only the conversion specifiers, but also whole parts of the pattern. In this case, for example, I want to pad [%-10t] %-22c
.
12.25.34,788 INFO [SomeThread] my.path.to.Class - First logged message
12.25.34,789 FATAL [Thread2] other.path.SecondClass - Second logged message
12.25.34.790 WARN [Scheduler] my.other.path.Class - Another message
The notation could be something like
%d{HH:mm:ss,SSS} %-5p %-32{[%t] %c} - %m%n
(note %-35{...}
- I want to pad whole content of this conversion specifier, just as one item)
I found this similar question, but there is no answer how to pad custom parts of the pattern, only answer with sample class extending PatternLayout
to generate a string in format Class:method
.
Additionally, I want to add padding between the two elements, as follows ([%t]
is left-justified, %c
is right-justified):
12.25.34,788 INFO [SomeThread] my.path.to.Class - First logged message
12.25.34,789 FATAL [Thread2] other.path.SecondClass - Second logged message
12.25.34.790 WARN [Scheduler] my.other.path.Class - Another message
It seems like the log4j library does not support it. So my question is: How can I achieve it? Possibly you can write a sample code. I believe it will help someone else, too.