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

时间:2018-02-26 14:37:30

标签: java spring spring-boot logging logback

在我的春季启动应用

中,Logback将我误解为错误
  

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 - [控制台]没有适用的操作,当前的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]]   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 - [策略]没有适用的操作,当前的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]]   ch.qos.logback.core.joran.spi.Interpreter@20中的错误:14 - [Loggers]没有适用的操作,当前的ElementPath是[[Configuration] [Loggers]]   ch.qos.logback.core.joran.spi.Interpreter@21:29中的错误 - [Root]没有适用的操作,当前的ElementPath是[[Configuration] [Loggers] [Root]]   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]]   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 here context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)       在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)       在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java: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)   

我的回溯配置是:

<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>

1 个答案:

答案 0 :(得分:2)

这可能是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>

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