DEV Community

loizenai
loizenai

Posted on

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

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay