Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j displaying log messages using %p

Tags:

java

log4j

now for a particular log message for the %p sign i wil get either debug or error or warning. can anyone tel me how to get only the first three letters. eg. only WAR for Warning

like image 956
user696266 Avatar asked Sep 13 '25 19:09

user696266


1 Answers

In log4j 2.x, you can truncate from the end:

Truncation from the end is possible by appending a minus character right after the period. In that case, if the maximum field width is eight and the data item is ten characters long, then the last two characters of the data item are dropped.

Link: https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout

So in this case, %.-3p should give WAR instead of WARNING.

like image 54
dylam Avatar answered Sep 16 '25 11:09

dylam