java - Logback 配置中的 BuferredIO 和 ImmediateFlush 属性

标签 java logging logback logback-classic

我正在将遗留应用程序迁移到 Spring Boot,并且遇到了以下问题:当我启动应用程序时,由于以下异常而失败:

Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:21 - no applicable action for [BufferedIO], current ElementPath is [[configuration][appender][BufferedIO]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:25 - no applicable action for [ImmediateFlush], current ElementPath is [[configuration][appender][ImmediateFlush]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:161) at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:207) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114) at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:299) at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:272) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:235) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:208) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:72) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338) at org.springframework.boot.SpringApplication.run(SpringApplication.java:309) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) at com.some_company.SomeApp.main(SomeApp.java:28)

因此 Logback 无法解析 BuferredIO 和 ImmediateFlush 属性。我试图查看他们的 docs但它似乎已经过时了,因为它说存在这样的属性+我发现例如对于 OutputStreamAppender 来说,它没有 immediateFlush 属性,而根据文档它应该有。

我找不到任何有关 Logback 现在是否仍支持以下属性的信息。您能否帮助并提出一些关于我如何才能达到与之前的属性相同的结果的想法?也许他们在其他地方:)

非常感谢!:)

更新:添加 Logback 配置快照:

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${logdir}/some-app.log</File>
        <Append>true</Append>        
        <BufferedIO>false</BufferedIO>
        <ImmediateFlush>true</ImmediateFlush>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>${logdir}/archive-some-app.%i.log.zip</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>20MB</MaxFileSize>
        </triggeringPolicy>

        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <fieldNames>
                <timestamp>timestamp</timestamp>
            </fieldNames>
        </encoder>
    </appender>

Logback 版本是 1.1.7(之前是迁移之前的版本)

最佳答案

虽然ImmediateFlushOutputStreamAppender 的有效配置属性(RollingFileAppender 扩展)在最新版本的 Logback 中(因此在最新文档中引用)这仅添加到 OutputStreamAppenderhere 2017 年 2 月。所以,immediateFlush不是 OutputStreamAppender 的有效属性(因此无法从 RollingFileAppender 访问)在 v1.1.7

这解释了以下错误:

no applicable action for [ImmediateFlush], current ElementPath is [[configuration][appender][ImmediateFlush]]

BufferedIO 是一个旧的配置属性,Logback 不再支持它。

这解释了以下错误:

no applicable action for [BufferedIO], current ElementPath is [[configuration][appender][BufferedIO]]

总之,您可能会考虑升级到最新的 Logback,然后删除 <BufferedIO>false</BufferedIO> 。或者,继续使用 v1.1.7 并删除这两个:<BufferedIO>false</BufferedIO><ImmediateFlush>true</ImmediateFlush> .

关于java - Logback 配置中的 BuferredIO 和 ImmediateFlush 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48183369/

相关文章:

java - Spark 强制 log4j

akka - 让 Akka 知道 Play 的 logback 配置

java - 小工具中的Logback+Swing

java - 为什么空布局和绝对位置在 Swing 中是不好的做法?

java - 神秘的 Ant 脚本

exception - 如何配置 log4j 不打印异常堆栈跟踪?

git log --stat 分支汇总

java - Log4j2:动态创建多个日志的日志文件

java - 在给出 NullPointerException 的 android Assets 中打开文本文件

java - 显示每个 ListView 项目的文本