no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
代码异常提示如下:16:59:58,897 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-error] - Active log file name: logs/error.log16:59:58,897 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender
·
代码异常提示如下:
16:59:58,897 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-error] - Active log file name: logs/error.log
16:59:58,897 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-error] - File property is set to [logs/error.log]
16:59:58,901 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@58:37 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
16:59:58,902 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:30 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
16:59:58,902 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@60:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
16:59:58,902 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@65:35 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
16:59:58,902 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@66:29 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
16:59:58,902 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@67:41 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
16:59:58,903 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:39 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
16:59:58,903 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@69:45 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
16:59:58,903 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:59:58,904 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@e2144e4 - Registering current configuration as safe fallback point
出现上述异常后,日志信息未按指定规则输出。
logback.xml 配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<configuration debug="false" scan="true" scanPeriod="1 seconds">
<contextName>logback</contextName>
<property name="LOG_HOME" value="logs"/>
<property name="maxHistory" value="7"/>
<!-- ConsoleAppender 控制台输出日志 -->
<!--ConsoleAppender 用于在屏幕上输出日志-->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} [%file : %line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!--全部日志 INFO WARN ERROR FATAL OFF-->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/log.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/log_%d{yyyyMMdd}.%i.log</fileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
<maxFileSize>50MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} [%file : %line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!--error 日志-->
<appender name="file-error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/error.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/error_%d{yyyyMMdd}.%i.log</fileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
<maxFileSize>20MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} [%file : %line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 开发、测试环境 -->
<springProfile name="dev,test">
<root level="debug">
<appender-ref ref="stdout"/>
</root>
</springProfile>
<!-- 生产环境 -->
<springProfile name="offline">
<root level="debug">
<appender-ref ref="stdout"/>
<appender-ref ref="file"/>
<appender-ref ref="file-error"/>
</root>
</springProfile>
</configuration>
本猿出现该问题情况说明:程序在开发环境、生产环境运行均正常,但在生产环境部署时,将配置信息移动至同级jar 下的config目录中时,出现上面异常。
部署目录结构如下:
原因跟spring加载配置文件优先级有关,解决方式如下:将logback.xml 日志中使用的springProfile节点相关内容去掉。
<!-- 开发、测试环境 -->
<!-- <springProfile name="dev,test"> -->
<!-- <root level="debug"> -->
<!-- <appender-ref ref="stdout"/> -->
<!-- </root> -->
<!-- </springProfile> -->
<!-- 生产环境 -->
<!-- <springProfile name="offline"> -->
<root level="debug">
<appender-ref ref="stdout"/>
<appender-ref ref="file"/>
<appender-ref ref="file-error"/>
</root>
<!-- </springProfile> -->
备注,按照此处链接分享的方式,未能解决问题,特此记录,可能跟我这边部署方式不一样吧。
更多推荐
已为社区贡献4条内容
所有评论(0)