簡體   English   中英

獲取 java.lang.IllegalStateException: Logback 配置錯誤檢測到錯誤

[英]Getting java.lang.IllegalStateException: Logback configuration error detected error

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]] ch.qos.logback.core.joran.spi.Interpreter@11:26 中的錯誤 - [pattern 沒有適用的操作], 當前電子 mentPath 是 [[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]] 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.Int erpreter@22:46 - [AppenderRef] 沒有適用的操作,當前 ElementPath 是 [[Configuration][Loggers][Root][AppenderRef]] ch.qos.logback.core.joran.spi.Interpreter@23:42 錯誤- [AppenderRef] 沒有適用的操作,當前 ElementPath 是 [[Configuration][Loggers][Root][AppenderRef]] 錯誤 in 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(Loggi ngApplicationListener.java:212) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) 在 org.springframework。 enter code here context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimplemulticasterSimpleApplicationEventSimpleApplicationEventMulticasterMulticaster .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) at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) at 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>

這可能是 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 以進行日志記錄)。

該錯誤可以通過使用解決

<appender name="Console"
            class="ch.qos.logback.core.ConsoleAppender">

代替

<Console name="Console" target="SYSTEM_OUT">

鏈接供參考

以下是您如何做到這一點的參考:-

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan = "true">

        <property name="LOGS" value="./logs" />
        <property resource ="application.yml"/>
        <springProperty name="NAME" source="spring.application.name" />
        <appender name="Console"
            class="ch.qos.logback.core.ConsoleAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>
                    %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
                </Pattern>
            </layout>
        </appender>
        
        <appender name="RollingFile"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOGS}/${NAME}.log</file>
        <encoder
            class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
        </encoder>

        <rollingPolicy
            class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily and when the file reaches 10 MegaBytes -->
            <fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>
     
    <root level="info">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />
    </root>

    <logger name="com.ms" level="trace" additivity="false">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />
    </logger>
    
    <logger name="org.springframework.core.env.PropertySourcesPropertyResolver" level="trace" additivity="true">
    </logger>

</configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM