简体   繁体   中英

Spring boot logback not logging to file

I am using the spring-boot-start-web dependency in my web mvc application and making use of logback. I have a logback-spring.xml file located in my static resources directory with the following config

<property name="MY_LOG_FILE" value="C:\mylog.log" />

<appender name="MY_APPENDER"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <encoder>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
    <file>${MY_LOG_FILE}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${MY_LOG_FILE}.%i</fileNamePattern>
    </rollingPolicy>
    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <MaxFileSize>10MB</MaxFileSize>
    </triggeringPolicy>

<logger name="com.mydomain.myapp" level="INFO" additivity="false">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="MY_APPENDER" />
</logger>

When I use the logger in my controllers it correctly logs to the console output, but the file is nowhere to be found. As far as what I can find online it looks like i'm setting it up correctly, but obviously I am not.

EDIT: It ended up being resolved by performing a Maven Update Project on the parent project, this project was part of a larger system of modules.

Put the logback-spring.xml in your resources directory,not static directory.

Build your project with maven,then Check if your target/classes directory has the logback-spring.xml

By default,If you put a logback.xml in the root of your classpath it will be picked up from there (or logback-spring.xml to take advantage of the templating features provided by Boot)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM