Kotlin SpringBoot configure Apache Log4j2
Apache Log4j2 is an upgrade to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides many of the improvements available in Logback while fixing some inherent problems in Logback’s architecture. The tutorial will introduce way to configure Apache Log4j2 with Kotlin SpringBoot.
I. Technologies
– Java 1.8
– Maven 3.6.1
– Spring Tool Suite – Version 3.9.0.RELEASE
– Spring Boot – 1.5.9.RELEASE
– Kotlin
II. Practice
We use SpringToolSuite to create a Kotlin SpringBoot project as below structure:
Step to do:
- Configure SpringBoot Log4j2 dependencies
- Create a Simple Controller
- Configure Log4j2.xml
- Build & Run
1. Configure SpringBoot Log4j2 dependencies
– Exclude logback from default log dependency of SpringBoot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
– Add Spring Web MVC dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
– Add Log4j2 dependency
Kotlin SpringBoot configure Apache Log4j2
Top comments (0)