1

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

线程“main”java.lang.IllegalStateException 中的异常:检测到 Logback 配置错误:ch.qos.logback.core.joran.spi.Interpreter@10:21 中的错误 - [BufferedIO] 没有适用的操作,当前 ElementPath 是 [[ configuration][appender][BufferedIO]]
ch.qos.logback.core.joran.spi.Interpreter@11:25 中的错误 - [ImmediateFlush] 没有适用的操作,当前 ElementPath 是 [[configuration][appender][ImmediateFlush] ]
在 org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:161) 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:207) 在 org.springframework.boot.logging .AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65) 在 org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50) 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114 ) 在 org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:272) 在 org.springframework.boot.logging 的 org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:299)。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) 在 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)爪哇:28)爪哇:28)

所以 Logback 无法解析 BufferredIO 和 ImmediateFlush 属性。我试图查看他们的文档,但它似乎已经过时,因为它说存在这样的属性+我发现例如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(之前在迁移之前)

4

1 回答 1

3

虽然是最新版本的 Logback 中OutputStreamAppender(扩展)ImmediateFlush的有效配置属性(因此在最新的文档中被引用),但它仅在 2017 年 2 月添加到此处。因此,它不是(因此是v1.1.7 中的 ) 无法访问RollingFileAppenderOutputStreamAppender immediateFlushOutputStreamAppenderRollingFileAppender

这解释了以下错误:

[ImmediateFlush] 没有适用的操作,当前 ElementPath 是 [[configuration][appender][ImmediateFlush]]

BufferedIO是 Logback 不再支持的旧配置属性。

这解释了以下错误:

[BufferedIO] 没有适用的操作,当前 ElementPath 是 [[configuration][appender][BufferedIO]]

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

于 2018-01-10T09:31:46.257 回答