jackson
jackson

Reputation: 349

log message print twice with java logback

I use logback to print log in my SpringBoot application. When I check out the log file, I found that, all log message print twice! It is so strange . Yeah, I have found some answer similar to my issue. But maybe they are not what I want.

here is my logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
    <property name="LOG_HOME" value="${user.home}/app/logs"/>
    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}-[%thread]-%-5level-%logger{50}: %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${LOG_HOME}/cloud-sync-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <!-- each file should be at most 10MB, keep 3 days worth of history, but at most 1GB -->
            <maxFileSize>10MB</maxFileSize>
            <maxHistory>3</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name ="ASYNC" class= "ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold >0</discardingThreshold>
        <queueSize>256</queueSize>
        <includeCallerData>true</includeCallerData>
        <appender-ref ref ="FILE"/>
    </appender>
    <root level="INFO">
        <appender-ref ref="Console"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="ASYNC"/>
    </root>
</configuration>

How can I make sure log messages appear only once. Thank you.

Upvotes: 2

Views: 2732

Answers (2)

M Aqib Naeem
M Aqib Naeem

Reputation: 197

In case someone wants to achieve same but keeping all root appenders.

Configure Springboot Application logger as "INFO" and additivity="false", you can add as many appenders as you like to the the root and they will not duplicate the banner.

<logger name="org.springframework.boot.SpringApplication" level="INFO" additivity="false" />

Upvotes: 0

Yogesh Prajapati
Yogesh Prajapati

Reputation: 4870

It is because you have added ASYNC and FILE for INFO.

Please remove one of them based on your requirement.

Upvotes: 1

Related Questions