question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring App Name is not resolved properly

See original GitHub issue

Having 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Sergey80commented, Mar 24, 2020

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.

 id 'org.springframework.boot' version '2.2.5.RELEASE'
   implementation("org.springframework.cloud:spring-cloud-starter-sleuth:2.2.2.RELEASE")
0reactions
apolischukcommented, Jul 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring boot application start without proper application name
Spring boot application start without proper application name · It's using embeded tomcat, thus it has its own port, and no need the...
Read more >
Resolving Failed to Configure a DataSource Error - Baeldung
In this short tutorial, we'll discuss what causes and what resolves the “Failed to configure a DataSource” error on a Spring Boot project....
Read more >
Confluence does not start due to Spring Application context ...
IllegalStateException: Spring Application context has not been set at com.atlassian.spring.container.SpringContainerContext.
Read more >
Spring Boot, Maven and Eclipse Errors and TroubleShooting ...
Approach 1 : Spring Boot Project; Detailed Example; Approach 2: Non Spring Boot Project; Java Application Context; XML Application Context.
Read more >
Use Key Vault references - Azure App Service - Microsoft Learn
Make Key Vault secrets available to your application code. ... If a reference is not resolved properly, the reference value will be used ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found