Tao*_*ama 6 log4j2 spring-boot
好吧,我有 3 个 spring 配置文件:dev、prod、test,我想在不同的配置文件中使用不同的 log4j2 配置。我检查了spring-boot 参考并按照它所说的方式进行了操作。但是当我运行 spring 应用程序时,我只得到下面的日志:
2018-03-05 09:52:32,194 main ERROR Error processing element SpringProfile ([Configuration: null]): CLASS_NOT_FOUND
2018-03-05 09:52:32,194 main ERROR Error processing element SpringProfile ([Configuration: null]): CLASS_NOT_FOUND
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索并计算了错误日志,但仍然无法找到springProfile标签不起作用的答案。
这是我的log4j2-spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<SpringProfile name="prod">
<Appenders>
<RollingFile name="RollingFile"
fileName="/home/prod/service.log"
filePattern="/home/prod/service.log.%d{yyyyMMddHH}"
append="true">
<PatternLayout pattern="[%level][%d{yyyy-MM-dd'T'HH:mm:ss.SSSXX}][%l] %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</SpringProfile>
<SpringProfile name="!prod">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%level][%d{yyyy-MM-dd'T'HH:mm:ss.SSSXX}][%l] %msg%n" />
</Console>
<File name="File" fileName="./logs/service.log" append="false">
<PatternLayout pattern="[%level][%d{yyyy-MM-dd'T'HH:mm:ss.SSSXX}][%l] %msg%n" />
</File>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="File"/>
<!--When WIP, you could uncomment the next line to show log to console.-->
<!--<AppenderRef ref="Console"/>-->
</Root>
</Loggers>
</SpringProfile>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
您的项目中缺少 Log4J2 spring boot 支持的依赖项。您需要添加org.apache.logging.log4j:log4j-spring-boot。将其添加为依赖项可以启用标签的使用SpringProfile。(此功能自2.15.0版本起可用)
人们可能会认为这是 Spring Boot Log4J2 集成的一个错误。
| 归档时间: |
|
| 查看次数: |
2073 次 |
| 最近记录: |