Closed moonlight200 closed 6 months ago
Thanks for reporting this, @moonlight200. As far as I can tell, Logback does not support escaping of the characters that have special meaning to its support for variable substitution. This means that we'd have to replace the problematic characters ({
, }
, (
, or )
) with something else or omit them entirely. I think we'll need to discuss this one as a team to see if we can agree on something. If you have any suggestions based on your experience please do share them.
I wonder if we could put the application name in a logback variable then use property{APPLICATION_NAME}
in the console pattern.
Thank you for the quick replies. From what I could see in the spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback
resources the application name is inserted into the format string of the log message. Maybe there is a way to only place a reference in the format string pass the name as an input instead. It looks like the suggestion from @philwebb is about just that. I am not sure if or how this is doable, as I don't have much experience with the internals of logback or spring boot.
@moonlight200 Out of interest, does setting logging.include-application-name
to false
"fix" the issue?
We're considering failing fast with an exception then giving users the choice of either changing their application name or disabling the feature.
With this config:
spring.application.name=Test Name (dev)
logging.include-application-name=false
Logging works fine:
2024-02-15T17:20:29.487+01:00 INFO 1302973 --- [ restartedMain] c.s.s.SpringLoggingTestApplicationKt : No active profile set, falling back to 1 default profile: "default"
The problem doesn't occur with Log4j2. With that in mind, this branch contains a fix that's Logback-specific.
The fix uses %property
to retrieve LOGGED_APPLICATION_NAME
. Unfortunately, %property
doesn't support default values so it will evaluate to null
when LOGGED_APPLICATION_NAME
hasn't been set. To overcome this, %replace
is used to turn null
into an empty string. This works, but I am a little wary of it as it's implemented using a regular expression which may have some performance implications.
An alternative to this would be to use a custom converter for the logged application name, similar to what we're already doing for the correlation ID.
We're going to look at a custom converter because we're worried about regex performance.
I recently upgraded to Spring Boot 3.2.2. After the update, all log messages appeared in one single line:
The 3.2 Release Notes state, that the application name is now included in the log messages. I had my application name setup with a
... (dev)
at the end which was the cause for this issue.Observed Behavior
On a new spring boot 3.2.2 project (I used Kotlin for both, the source code and Gradle config):
)
(e.g.spring.application.name=Test Name (dev)
), all logs appear in a single line (see example above)(
but no)
everything is fine(
and)
, the behavior is the same as with only the closing bracket[
and/or]
caused an issue}
but no opening{
, e.g.spring.application.name=Test Name }dev
everything after the}
is cut away:{
and}
, e.g.spring.application.name=Test Name {dev}
everything looks fine:{
but no}
, e.g.spring.application.name=Test Name {dev
the application fails to start:Expected behavior
Regardless of the appearance of any of
([{}])
in the application name, the log output is formatted correctly