获取 java.lang.IllegalStateException: Logback 配置错误检测到错误

Ank*_*kur 7 java logging spring logback spring-boot

Logback 在我的 Spring Boot 应用程序中让我低于错误

java.lang.IllegalStateException:检测到 Logback 配置错误:ch.qos.logback.core.joran.spi.Interpreter@3:16 中的错误 - [Appenders] 没有适用的操作,当前 ElementPath 是 [[Configuration][Appenders]] ch.qos.logback.core.joran.spi.Interpreter@4:53 中的错误 - [Console] 没有适用的操作,当前 ElementPath 是 [[Configuration][Appenders][Console]] ch.qos.logback 中的错误。 core.joran.spi.Interpreter@5:92 - [PatternLayout] 没有适用的操作,当前 ElementPath 是 [[Configuration][Appenders][Console][PatternLayout]] ch.qos.logback.core.joran.spi 中的错误.Interpreter@9:49 - [RollingFile] 没有适用的操作,当前 ElementPath 为 [[Configuration][Appenders][RollingFile]] ch.qos.logback.core.joran.spi.Interpreter@10:28 错误 - 否[PatternLayout] 的适用操作,当前 ElementPath 是 [[Configuration][Appenders][RollingFile][PatternLayout]] 错误 in ch.qos.logback.core.joran.spi.Interpreter@11:26 - [pattern] 没有适用的操作,当前 ElementPath 是 [[ Configuration][Appenders][RollingFile][PatternLayout][pattern]] ch.qos.logback.core.joran.spi.Interpreter@13:23 中的错误 - [Policies] 没有适用的操作,当前 ElementPath 是 [[Configuration] [Appenders][RollingFile][Policies]] ch.qos.logback.core.joran.spi.Interpreter@14:59 中的错误 - [SizeBasedTriggeringPolicy] 没有适用的操作,当前 ElementPath 是 [[Configuration][Appenders][RollingFile] ][Policies][SizeBasedTriggeringPolicy]] ch.qos.logback.core.joran.spi.Interpreter@16:50 中的错误 - [DefaultRolloverStrategy] 没有适用的操作,当前 ElementPath 是 [[Configuration][Appenders][RollingFile][DefaultRolloverStrategy]] 错误 in ch.qos.logback.core.joran.spi.Interpreter@20:14 - [Loggers] 没有适用的操作,当前 ElementPath 是 [[配置][记录器]] ch.qos.logback.core.joran.spi.Interpreter@21:29 中的错误 - [Root] 没有适用的操作,当前 ElementPath 为 [[Configuration][Loggers][Root]] ERROR ch.qos.logback.core.joran.spi.Interpreter@22:46 - [AppenderRef] 没有适用的操作,当前 ElementPath 是 [[Configuration][Loggers][Root][AppenderRef]] ch.qos.logback 中的错误.core.joran.spi.Interpreter@23:42 - [AppenderRef] 没有适用的操作,当前 ElementPath 是 [[Configuration][Loggers][Root][AppenderRef]] ch.qos.logback.core.joran 中的错误。 spi.Interpreter@25:76 - [Logger] 没有适用的操作,当前 ElementPath 为 [[Configuration][Loggers][Logger]] 错误 in ch.qos.logback.core.joran.spi.Interpreter@26:44 - [AppenderRef] 无适用操作,当前 ElementPath 为 [[Configuration][ Loggers][Logger][AppenderRef]] ch.qos.logback.core.joran.spi.Interpreter@27:40 中的错误 - [AppenderRef] 没有适用的操作,当前 ElementPath 是 [[Configuration][Loggers][Logger] [AppenderRef]] ch.qos.logback.core.joran.spi.Interpreter@29:68 中的错误 - [Logger] 没有适用的操作,当前 ElementPath 是 [[Configuration][Loggers][Logger]] ch 中的错误。 qos.logback.core.joran.spi.Interpreter@30:44 - [AppenderRef] 没有适用的操作,当前 ElementPath 是 [[Configuration][Loggers][Logger][AppenderRef]] 在 org.springframework.boot.logging。 logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162) 在 org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) 在 org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56) 在 org.springframework.boot.logging.logback .LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115) 在 org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308) 在 org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276) 在org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239) 在 org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) 在 org.springframework。enter code herecontext.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 在 org.springframework.context.event.SimplecastApplicationEventMulticaster.java:165 122) 在 org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) 在 org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) 在 org.springframework.boot.SpringApplication.prepareEnvironment (SpringApplication.java:325) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:296) 在 org.springframework.boot。SpringApplication.run(SpringApplication.java:1118) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)

我的logback配置是:

<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <RollingFile name="RollingFile" fileName="${sys:home}/logs/log"
            filePattern="${sys:home}/logs/mylog-%i.log" bufferedIO="false"
            immediateFlush="true" append="true">
            <PatternLayout>
                <pattern>%d %p [%t] %c{1.} %m%n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="20 MB" />
            </Policies>
            <DefaultRolloverStrategy max="100" />
        </RollingFile>
    </Appenders>

    <Loggers>
        <Root level="error">
            <AppenderRef ref="RollingFile" />
            <AppenderRef ref="Console" />
        </Root>
        <Logger name="org.springframework" level="info" additivity="false">
            <AppenderRef ref="RollingFile"></AppenderRef>
            <AppenderRef ref="Console"></AppenderRef>
        </Logger>
        <Logger name="com.myproj" level="debug" additivity="false">
            <AppenderRef ref="RollingFile"></AppenderRef>
        </Logger>
    </Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)

mp3*_*415 8

这可能是 log4j2 配置。为了支持它,您的 Spring Boot pom 文件必须更新如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

在此处查看更多详细信息:https : //docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-logging(第 8.2 节配置 Log4j 以进行日志记录)。