Remove outdated comments
1 file changed
tree: 578b58e1834c84b2f15a32976f52b42a19af05ce
  1. log4j-api-kotlin/
  2. log4j-api-kotlin-benchmark/
  3. log4j-api-kotlin-sample/
  4. src/
  5. .asf.yaml
  6. .gitignore
  7. CHANGELOG.adoc
  8. checkstyle-header.txt
  9. CODE_OF_CONDUCT.md
  10. CONTRIBUTING.md
  11. LICENSE.txt
  12. NOTICE.txt
  13. pom.xml
  14. README.md
README.md

Apache Log4j 2 (Kotlin API)

Log4j Kotlin API is a Kotlin logging facade based on Log4j 2. Log4j Kotlin API provides Log4j 2 as its default logging implementation, but this is not strictly required (e.g., this API can also be used with Logback or other Log4j 2 API provider implementations). Idiomatic Kotlin features are provided as an alternative to using the Log4j 2 Java API.

Maven Central Build Status

Pull Requests on Github

By sending a pull request you grant the Apache Software Foundation sufficient rights to use and release the submitted work under the Apache license. You grant the same rights (copyright license, patent license, etc.) to the Apache Software Foundation as if you have signed a Contributor License Agreement. For contributions that are judged to be non-trivial, you will be asked to actually signing a Contributor License Agreement.

Usage

Users should refer to Maven, Ivy and Gradle Artifacts on the Log4j website for instructions on how to include Log4j into their project using their chosen build tool.

Using the Kotlin API is as simple as mixing in the Logging interface to your class. Example:

import org.apache.logging.log4j.kotlin.Logging

class MyClass: BaseClass, Logging {
    fun doStuff() {
        logger.info("Doing stuff")
    }
    
    fun doStuffWithUser(user: User) {
        logger.info { "Doing stuff with ${user.name}." }
    }
}

The Logging interface can also be mixed into object declarations, including companions. This is generally preferable over the previous approach as there is a single logger created for every instance of the class.

import org.apache.logging.log4j.kotlin.Logging

class MyClass: BaseClass {
    companion object : Logging
    
    // ...
}

Alternatively, a more traditional style can be used to instantiate a logger instance:

import org.apache.logging.log4j.kotlin

class MyClass: BaseClass {
    val logger = logger()
    
    // ...
}

The function logger() is an extension function on the Any type (or more specifically, any type T that extends Any).

Documentation

The Kotlin‘s Log4j 2 User’s Guide is available here.

Requirements

Log4j Kotlin API requires at least Java 8. This also requires Log4j 2 API, but it is specified as transitive dependencies automatically if you are using SBT, Maven, Gradle, or some other similar build system. This also requires Log4j 2 Core (or possibly an other implementation of Log4j 2 API) as a runtime dependency. Some Log4j 2 Core features require optional dependencies which are documented in the Log4j 2 manual.

The Kotlin API requires the full kotlin-reflect dependency in order to name loggers appropriately, and optionally kotlinx-coroutines-core to set the mapped diagnostic context for a coroutine.

The Kotlin dependencies are not exposed transitively -- for maximum compatibility logging-log4j-kotlin is built with Kotlin 1.3, producing binaries that should be forward compatible. For maximum compat, the Kotlin dependencies are “provided” i.e. consumers of this library need to depend on them directly rather than transitively, thus avoiding version clashes.

License

Apache Log4j 2 is distributed under the Apache License, version 2.0.

Download

How to download Log4j, and how to use it from Maven, Ivy and Gradle. You can access the latest development snapshot by using the Maven repository https://repository.apache.org/snapshots, see Snapshot builds.

Issue Tracking

Issues, bugs, and feature requests should be submitted to the GitHub issues page for this project.

Pull request on GitHub are welcome; corresponding GitHub issues should be referenced in the PR.

Building From Source

Log4j Kotlin API requires Maven 3 and Java 8 to build. To install to your local Maven repository, execute the following:

mvn install

Contributing

We love contributions! Take a look at our contributing page.