如何配置 Spring Boot logback RollingFileAppender 并拥有执行器日志文件?

Ser*_*tin 6 logback spring-boot spring-boot-actuator

据我了解,/logfile 执行器仅logging.file=在 application.properties 文件中可用。

但是对于我的日志记录,我需要带有 SizeAndTimeBasedRollingPolicy 的 RollingFileAppender 文件附加器。

是否可以在 application.properties 中配置 RollingFileAppender?

如果我在 logging-spring.xml 中配置 RollingFileAppender,则会出现错误:

java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - 'File' option has the same value "log/scratch6.log" as that given for appender [FILE] defined earlier.

是否可以通过 RollingFileAppender 获得日志文件并具有 /logfile 执行器?

Vij*_*Ram 5

我遇到了同样的问题。这是我发现的

logging.file - 实际上创建一个文件。当您在 logback-spring.xml 中声明 ${LOG_FILE} 时,它会检测到冲突。附加程序和文件名具有相同的值。

我最终这样做了(附加 .log 以便区分附加程序和文件)

application.properties:logging.file=/opt/fff/logs/file_debug

logback-spring.xml:

     <file>${LOG_FILE}.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} - %msg%n
        </Pattern>
    </encoder>
Run Code Online (Sandbox Code Playgroud)

..

但是,除了 /opt/fff/logs/file_debug.log 之外,它还会创建另一个文件 /opt/fff/logs/file_debug