crandyzhang
crandyzhang

Reputation: 21

logback-spring.xml does not work when deploy on tomcat

I hava create spring boot project with Java 8, and I am using external Tomcat container to deploy. I hava a logbakc-spring.xml as follows:

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/log/hfxn.%d{yyyy-MM-dd}.log</fileNamePattern>
    <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder>
        <charset>utf-8</charset>
        <Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
    </encoder>
</appender>

But, when I build into war, and deploy on Tomcat, I cannot find the log file in the path where I specified, and , I don't know why?

Upvotes: 1

Views: 2401

Answers (2)

Sumit Chawla
Sumit Chawla

Reputation: 116

A logback file named logback-spring.xml works well if your project is spring-boot compatible, but when you deploy your project as war into tomcat, this file is not picked because of naming a constraint on logback file.

A logback file can have only 1 of these 3 allowed names:

  • logback-test.xml
  • logback.groovy
  • logback.xml

As soon as you change the name of the file as one of the above, logback config will start working with war package deployed over Tomcat.

Upvotes: 2

Jeff
Jeff

Reputation: 953

Do you see the logback file found in the console messages? Try naming the file logback.xml, which is a standard logback name that it searches for at startup. Also, ensure the file is at the top level in the jar, not nested in a subdirectory.

Upvotes: 0

Related Questions