Well, I have 3 spring profiles: dev, prod, test, and I want to use different log4j2 configuration in different profiles. I checked the the spring-boot reference and followed the way it said. But when I run spring application, I only get the log below:
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
I googled and stackoverflowed the error log, and can't still find an answer why springProfile
tag didn't work.
And here is my 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>