Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot logging - extraneous hyphen at start of every log entry

I am trying to eliminate a leading hyphen from our console and file logs in SpringBoot 1.3.5.RELEASE with default logback config.

Logging pattern looks like:

logging:
  pattern:
    console: '%d{yyyy-MM-dd HH:mm:ss.SSS} %clr([${spring.application.name}]){red} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %X{req.requestId} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%rEx}'

The file log pattern is similar, without the color coding. Both output every line after the first with a leading hyphen, which is making our syslog - logstash - grok filtering trickier. Example output:

2016-06-21 11:52:00.576 [my-app] INFO etc.. (application started)
-2016-06-21 11:52:00.583 [my-app] DEBUG etc..
-2016-06-21 11:52:00.583 [my-app] INFO etc..

I can't see anything in the docs mentioning this behaviour. Welcome any advice on how to eliminate it, if possible!

Update

Thanks to Edgar's answer below, it turns out this was caused by the following at the end of our logging pattern:

${LOG_EXCEPTION_CONVERSION_WORD:-%rEx}

I replaced it with:

${LOG_EXCEPTION_CONVERSION_WORD:%rEx}

et voila, the hyphen at the start of the following line disappears. See http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-custom-log-configuration

like image 955
Tom Bunting Avatar asked Jun 21 '16 10:06

Tom Bunting


2 Answers

The problem is in this part of logging.pattern.console:

${LOG_EXCEPTION_CONVERSION_WORD:-%rEx}

:- is Logback's default value delimiter and is what you should use in logback.xml. However, you're configuring things in application.properties where it's Spring Framework's default value delimiter (:) which should be used.

As you've used :-, you're saying use the value of LOG_EXCEPTION_CONVERSION_WORD and, if it's not set, use -%rEx instead.

The correct syntax is:

${LOG_EXCEPTION_CONVERSION_WORD:%rEx}
like image 104
Andy Wilkinson Avatar answered Nov 16 '22 23:11

Andy Wilkinson


It's hard to diagnose without your providing the full logging format. I'm seeing something similar in our code, and it seems to be related to including this in the format:

${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}

If you're using it, then the hyphen may be the one before the %w. I'm not sure what the intended purpose of this is. If I find it, I'll add it to my answer.

like image 9
Edgar Ngwenya Avatar answered Nov 17 '22 00:11

Edgar Ngwenya