Search code examples
javalogback

Having space in front of logged messages in logback


My Logback pattern in logback.xml file as follows

<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} %yellow([%X{Auth-Scopes:-},%X{Auth-Principal:-},%X{Auth-Organization:-}]) %magenta(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m %n ${LOG_EXCEPTION_CONVERSION_WORD:-%xEx}</pattern>

My problem is there is space in front of log lines from above pattern as follows

2021-08-18 03:40:00.017 DEBUG [test-service,,,] [,,] 1 --- [test-7] a.b.c.Test : Test

I am still trying to figure out what this cause for some time. Any help would be really appreciated .


Solution

  • Last parameter causes the problem. You can try this one;

            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} %yellow([%X{Auth-Scopes:-},%X{Auth-Principal:-},%X{Auth-Organization:-}]) %magenta(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m ${LOG_EXCEPTION_CONVERSION_WORD:-%xEx} %n</Pattern>