Log4j2 for Kotlin

Motivation

Logging is a common good practice in software engineering. It enables you to monitor applications in production to gather information about crashes and other malfunctions for further analysis. It is the “little brother” of debugging and often a precursor for setting up test cases which can lead to reproducing the bugs on the developers machine.

Log4j2 is version 2 of the very famous Apache logging library log4j from the Java ecosystem.

This article describes a minimal working solution for log4j2 with Kotlin and Gradle.

Dependencies

To get started with log4j2 add the following lines to your build.gradle file in the dependency section:

compile "org.apache.logging.log4j:log4j-api-kotlin:1.0.0"
compile "org.apache.logging.log4j:log4j-api:2.11.1"
compile "org.apache.logging.log4j:log4j-core:2.11.1"

Configuration

Continue reading “Log4j2 for Kotlin”

Kotlin Scripts with Gradle

If you are using gradle and you want to run a Kotlin script you have to add the following to your build.gradle file

dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib"
     compile group: 'org.jetbrains.kotlin', name: 'kotlin-script-runtime', version: '1.4.32'
}