SpringBoot logging - extraneous hyphen at start of every log entry
Asked Answered
P

3

18

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

Pelfrey answered 21/6, 2016 at 10:59 Comment(0)
B
9

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.

Bordello answered 21/6, 2016 at 12:29 Comment(2)
ah, so simple - just removed the hyphen from ${LOG_EXCEPTION_CONVERSION_WORD:%rEx}. I hadn't included it as I didn't think it was relevant.. will update my question with the full logging pattern - thanks!Pelfrey
how can I apply filters to it?Tram
P
22

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}
Pooka answered 21/6, 2016 at 14:26 Comment(1)
Document link is here, search 'you should use Spring Boot’s syntax'Adur
B
9

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.

Bordello answered 21/6, 2016 at 12:29 Comment(2)
ah, so simple - just removed the hyphen from ${LOG_EXCEPTION_CONVERSION_WORD:%rEx}. I hadn't included it as I didn't think it was relevant.. will update my question with the full logging pattern - thanks!Pelfrey
how can I apply filters to it?Tram
E
0

The suggested answers are actually slightly wrong, or at least are missing some details of what is happening.

If you replace ${LOG_EXCEPTION_CONVERSION_WORD:-%rEx} with ${LOG_EXCEPTION_CONVERSION_WORD:%rEx}, Spring will interpolate it into %rEx when it parses the property file (unless there happens to be a property LOG_EXCEPTION_CONVERSION_WORD available at that time).

LOG_EXCEPTION_CONVERSION_WORD is actually a System property provided by LoggingSystem and it's intended to be interpolated by Logback (which uses the ":-" syntax for default values).

You can fix the issue by defining a Spring property for the dollar character

dollar: $

Then replace ${LOG_EXCEPTION_CONVERSION_WORD:-%rEx} with:

${dollar}{LOG_EXCEPTION_CONVERSION_WORD:-%rEx}

thus bypassing Spring property interpolation. Then Logback will take care of interpolating the resulting pattern.

Eliciaelicit answered 26/5, 2023 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.