ttlasdd 2025-04-22 17:08 采纳率: 6.3%
浏览 30

日志异常logback

ERROR in ch.qos.logback.core.joran.spi.Interpreter@105:35 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]如何解决

  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2025-04-22 17:08
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    问题解答

    你遇到了日志异常logback的问题,错误信息是ERROR in ch.qos.logback.core.joran.spi.Interpreter@105:35 - no applicable action for [springProfile]

    这个错误是因为logback配置文件中没有找到对应的springProfile配置。springProfile是logback的配置文件中的一种配置方式,可以根据不同的环境配置不同的日志级别、日志文件路径等。

    解决方案:

    1. 在logback配置文件中添加springProfile配置,例如:
    <configuration>
        <springProfile name="dev">
            <!-- dev环境下的日志配置 -->
        </springProfile>
        <springProfile name="prod">
            <!-- prod环境下的日志配置 -->
        </springProfile>
    </configuration>
    
    1. 在spring配置文件中添加springProfile的配置,例如:
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="logbackConfig" class="ch.qos.logback.classic.joran.JoranConfigurator">
            <property name="configFile" value="logback.xml"/>
        </bean>
    
        <springProfile name="dev">
            <bean id="logbackConfig" class="ch.qos.logback.classic.joran.JoranConfigurator">
                <property name="configFile" value="logback-dev.xml"/>
            </bean>
        </springProfile>
    
        <springProfile name="prod">
            <bean id="logbackConfig" class="ch.qos.logback.classic.joran.JoranConfigurator">
                <property name="configFile" value="logback-prod.xml"/>
            </bean>
        </springProfile>
    
    </beans>
    
    1. 在logback配置文件中使用springProfile的配置,例如:
    <configuration>
        <springProfile name="dev">
            <appender name="FILE-APPENDER" class="ch.qos.logback.core.FileAppender">
                <file>log/dev.log</file>
                <encoder>
                    <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
                </encoder>
            </appender>
        </springProfile>
        <springProfile name="prod">
            <appender name="FILE-APPENDER" class="ch.qos.logback.core.FileAppender">
                <file>log/prod.log</file>
                <encoder>
                    <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
                </encoder>
            </appender>
        </springProfile>
    </configuration>
    

    这样,在不同的环境下,logback配置文件将根据springProfile的配置来选择不同的日志配置。

    评论

报告相同问题?

问题事件

  • 创建了问题 4月22日