简体   繁体   English

我的记录器没有使用 Spring 创建 RollingFile(使用 logback.xml 配置)

[英]My logger does not create a RollingFile with Spring (config with logback.xml)

I generate a spring boot project, and I want to log in an external file.我生成了一个 spring 引导项目,我想登录一个外部文件。

I choose to use Logback implementation, and here is my logback.xml file:我选择使用 Logback 实现,这里是我的logback.xml文件:

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

<configuration>

    <property name="LOG_PATH" value="./logs" />
    
    <appender name="CONSOLE"
        class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)]
                %yellow(%C{1.}): %msg%n%throwable
            </Pattern>
        </layout>
    </appender>

    <appender name="SAVE_TO_FILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/spring-boot-logger.log</file>
        <encoder
            class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
        </encoder>
    </appender>

    <!-- LOG everything at INFO level -->
    <root level="INFO">
        <appender-ref ref="SAVE_TO_FILE" />
        <appender-ref ref="CONSOLE" />
    </root>

</configuration>

I use to log with the classic line of code to log:我用经典的代码行来记录日志:

LoggerFactory.getLogger(CustomLogger.class);

I know that there is an implementation by default, and suspect my logback.xml (which is as the root of the project) is not taking in consideration.我知道默认情况下有一个实现,并且怀疑我的logback.xml (作为项目的根)没有考虑到。

Is there somewhere I have to specify the name of the file, or import it in my application as a resource?我是否必须在某个地方指定文件的名称,或者将其作为资源导入我的应用程序中?

OK,好的,

I had to put the logback.xml in the main path of the project.我不得不将logback.xml放在项目的main路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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