1
votes

I have two Spring boot applications - Application1 and Application2. Both applications are using Spring Cloud Sleuth. Both applications are deployed on same external tomcat. Below are the details of configurations - - To provide application name I have added separate bootstrap.yml file for each application in resources folder. - I have also provided active profile in bootstrap.yml file. - Application name is also added in application-${profile}.properties file as well. - After doing that I have added logback-spring.xml in classpath. Now when I start tomcat server with both applications I am getting first application name in Spring Cloud Sleuth logs for both applications.

I am using Spring boot 1.4.1 and Spring cloud sleuth 1.0.10

EDIT: I have added application name in bootstrap.yml but still I am facing same issue

2

2 Answers

1
votes

As we write in the docs (I think we do write about it) you have to provide the name in bootstrap yaml when providing your custom logback. Please check the docs where we describe how to work with custom logback. http://cloud.spring.io/spring-cloud-sleuth/spring-cloud-sleuth.html

1
votes

We had a similar problem in our project where we deployed two spring boot wars in one ibm liberty web container. We fixed it by providing a custom logback-spring.xml. Following are the configurations that fixed it: logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>

<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<property name="LOG_LEVEL_PATTERN" value="%clr(%5p) %clr([${springAppName},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]){yellow}" />
<!-- You can override this to have a custom pattern -->
<property name="CONSOLE_LOG_PATTERN"
          value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<appender name="FILE"
          class="ch.qos.logback.core.rolling.RollingFileAppender">
    <encoder>
        <pattern>${CONSOLE_LOG_PATTERN}</pattern>
    </encoder>

    <file>${server.output.dir}logs/myapplication1.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${server.output.dir}logs/myapplication1%d{yyyy-MM-dd}.log</fileNamePattern>
        <!--<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
            <!--<maxFileSize>1MB</maxFileSize>-->
        <!--</timeBasedFileNamingAndTriggeringPolicy>-->
    </rollingPolicy>
</appender>

<logger name="com.sample.controllers.MyController" level="DEBUG" additivity="false">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
</logger>
<logger name="org.springframework.jdbc.core.StatementCreatorUtils" level="TRACE" additivity="false">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
</logger>

<root level="INFO">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
</root>

Make sure it is included in classpath by maven

 <profiles>
        <profile>
            <id>default</id>
            <activation>
              <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/application.properties</include>
                            <include>**/*.xml</include>
                            <include>**/*.yml</include>
                        </includes>
                    </resource>
                </resources>
            </build>
        </profile>
</profiles>

And add the following entry in your src/main/resources/bootstrap.yml

spring: application: name: myapplication1 jmx: default-domain: myapplication1

Have this configuration in each of the two spring boot applications with different application names