Mirror of Apache Log4j Scala support
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
sample/src/main
src
.gitignore
.travis.yml
BUILDING.md
CONTRIBUTING.md
Jenkinsfile
LICENSE.txt
NOTICE.txt
README.md
build.sbt
create-distributions.sh
sbt
version.sbt

README.md

Apache Log4j 2 Scala API

Log4j Scala API is a Scala logging facade based on Log4j 2. This supports Scala 2.10, and 2.11 on Java 7 at minimum, and Scala 2.12 on Java 8 at minimum. Log4j Scala 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 Scala features are provided as an alternative to using the Log4j 2 Java API.

Note that this Scala API was versioned and released in sync with Log4j up until version 2.8.2, but from now on it will be versioned and released independently, that's why the version was bumped to 11.0.

Jenkins Status Travis Status

Usage

SBT users can add the following dependencies to their build.sbt file:

libraryDependencies ++= Seq(
  "org.apache.logging.log4j" %% "log4j-api-scala" % "11.0",
  "org.apache.logging.log4j" % "log4j-api" % "2.11.0",
  "org.apache.logging.log4j" % "log4j-core" % "2.11.0" % Runtime
)

Basic usage of the API:

import org.apache.logging.log4j.scala.Logging
import org.apache.logging.log4j.Level
 
class MyClass extends BaseClass with Logging {
  def doStuff(): Unit = {
    logger.info("Doing stuff")
  }
  def doStuffWithLevel(level: Level): Unit = {
    logger(level, "Doing stuff with arbitrary level")
  }
  def doStuffWithUser(user: User): Unit = {
    logger.info(s"Doing stuff with ${user.getName}.")
  }
}

Documentation

The Log4j Scala API is documented in more detail in the Log4j 2 manual and in the ScalaDocs.

Requirements

Log4j Scala API requires at least Java 7 for Scala 2.10/2.11, or Java 8 for Scala 2.12. 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.

License

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

Download

How to download Log4j, and how to use it from SBT, 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 JIRA issue tracking system for this project.

Pull request on GitHub are welcome, but please open a ticket in the JIRA issue tracker first, and mention the JIRA issue in the Pull Request.

Building From Source

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

./sbt "+ publishM2"

Contributing

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