Spring App Name is not resolved properly
See original GitHub issueHaving next logback custom config: `<?xml version="1.0" encoding="UTF-8"?> <configuration debug="true"> <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="spring.application.name" source="spring.application.name"/>
<property name="CONSOLE_LOG_PATTERN" value="${spring.application.name} ${LOG_LEVEL_PATTERN} %n"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>`
I got next in console:
cm DEBUG [-,,,]
So, as you can see application name is taken from spring config correctly, but TraceEnvironmentPostProcessor generetes wrong format for log level pattern in situation when Zipkin service name is absent but Spring App Name is present.
map.put("logging.pattern.level", "%5p [${spring.zipkin.service.name:" + "${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]");
https://github.com/spring-cloud/spring-cloud-sleuth/blob/e6b78d267fca2d7dfe5e19e571dc30dff7b00bd4/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceEnvironmentPostProcessor.java#L51
You missed - after spring.zipkin.service.name:
So, correct format is:
%5p [${spring.zipkin.service.name:-${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]
P.S. Truly speaking, I don’t understand why you did implement that post processor. Why should people use formatting like that? I think it is better to pass variables to MDC as it happens right now and let people configure logging as they want.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
so, still use bootstrap.yml.? I use latest deps now. and it ignores the application.yaml it reads the application name from the bootstrap.yml.
Thanks for your response @marcingrzejszczak , Not sure how to write test here… This is input data for Logback, so I assume this is the correct place for tests and I’m sure they have it ))). If you remove bootstrap.yml or just imagine that developers don’t configure service name at all, you will see [-,]. Have you ever wondered why we have dash here? Thats how Logback resolves it. If everything was fine we would see [,] output.