25 Sep 2015
comments powered by Disqus
Spring boot: use YAML to configure log4j2
Let’s see how to use YAML to configure log4j2 on a Spring boot application.
Maven
Basically, you need to exclude from your pom.xml the dependency tospring-boot-starter-logging
and add instead
spring-boot-starter-log4j2
. Then to work with YAML you have to add the dependency to jackson-dataformat-yaml
.
If your project does not depend on
spring-boot-starter-web
because it is not web. Then you will need to add this dependencycom.fasterxml.jackson.core:jackson-databind
.
YAML
The configuration goes in a file named log4j2.yml
located in the folder resources
. Hereunder is an example of
configuration. There are two
appenders, console
and
rolling file
then, there is the root logger and two specialized loggers for two classes.
Class
Examples using slf4j:
- In Groovy.
- In Java.