Logo

dev-resources.site

for different kinds of informations.

Kotlin SpringBoot configure Apache Log4j2

Published at
5/5/2021
Categories
kotlin
springboot
log4j2
Author
loizenai
Categories
3 categories in total
kotlin
open
springboot
open
log4j2
open
Author
8 person written this
loizenai
open
Kotlin SpringBoot configure Apache Log4j2

Kotlin SpringBoot configure Apache Log4j2

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/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:

Kotlin SpringBoot configure Apache Log4j2 - project 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

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-springboot-configure-apache-log4j2

Featured ones: