I have Spring Boot application and I want to use log4j2 instead of logback. I've already done all the necessary steps to exclude spring-boot-starter-logging from spring-boot-starter-web and added spring-boot-starter-log4j2 dependency. When I add log4j2.properties file under resources folder it works correct and I can see logs. But when I change file name to, lets say log4j2-demo.properties and set logging.config=classpath:log4j2-demo.properties nothing prints to console. For testing purpose I've set different name for lo4gj2 file in logging.config and it gives error with file not found and I think logging.config property actually working and reading my properties file.
application.properties file:
spring.profiles.active=dev
application-dev.properties file:
logging.config=classpath:log4j2-demo.properties
log4j2 properties file:
status=debug
name=PropertiesConfig
#
filters=threshold
#
filter.threshold.type=ThresholdFilter
filter.threshold.level=debug
#
appenders=console
#
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
#
rootLogger.level=info
rootLogger.appenderRefs=stdout
rootLogger.appenderRef.stdout.ref=STDOUT
my application structure:
src
main
java
resources
application.properties
application-dev.properties
log4j2-demo.properties
pom.xml :
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.graylog2.log4j2</groupId>
<artifactId>log4j2-gelf</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.zalando/logbook-spring-boot-starter -->
<dependency>
<groupId>org.zalando</groupId>
<artifactId>logbook-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
...