Remove whitespaces from logback message if a variable value is empty

Viewed 233

I use the following logback pattern:

<pattern>%X{version} %d{HH:mm:ss.SSS} %.-1level %C{0}:%M:%L %msg %n</pattern>

This produces a nice output if version is set but there are valid cases when it can be empty.

In this case, there is a leading whitespace in every logline (resulting from the space between %X{version} and %d{HH:mm:ss.SSS}).

The simple solution is to remove the whitespace from the pattern and append it to the value of version. Is there a more elegant way to solve this?

0 Answers
Related