I know how to output classname and methodname with log4j, both fields can be aligned and padded separately, e.g. this pattern:
[%d{ISO8601}] %-5p %-10C{1}:%-10M %m%n
produces something like:
[2012-09-20 08:25:12,111] WARN Class :method Logtext1 which should align
[2012-09-20 08:25:12,111] WARN ClassTwo :methodName Logtext2 which should align
This will align the logged text (in most cases), but the classname and methodname are ugly spaced.
So what I would like to output is something like:
[2012-09-20 08:25:12,111] WARN Class:method Logtext1 which should align
[2012-09-20 08:25:12,111] WARN ClassTwo:methodName Logtext2 which should align
Is this possible using only configuration?
Can you suggest another way of outputting methodname and classname, keeping the logged message text aligned?
It seems like this is not possible using only configuration.
The next simpler solution seems to be a custom PatternLayout, which then can be used in the log4j.ini with the character ‘b’:
log4j.appender.filelog.layout= your.full.namespace.BPatternLayout
log4j.appender.filelog.layout.ConversionPattern=[%d{ISO8601}] %-5p %-30b %m%n
Hope it helps someone else, too.
BPatternLayout.java:
BPatternParser.java: