Log4j Scala API is a Scala logging facade based on Log4j 2. Support for Scala versions 2.10, 2.11, and 2.12 is provided, and experimental support for pre-release versions of 2.13 is also provided. Log4j Scala API uses Log4j 2.x as its logging backend by default, but this can also be replaced with compatible libraries (e.g., Logback). While this library is not required to use Log4j API in Scala, it does provide idiomatic Scala APIs which are friendlier to use in Scala programs than the Java APIs.

Usage

Using the Scala API is as simple as mixing in the Logging trait to your class. Example:

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}.")
  }
}

API Documentation

Scala Version API Link

Scala 2.10

ScalaDocs

Scala 2.11

ScalaDocs

Scala 2.12

ScalaDocs

Scala 2.13

ScalaDocs

Configuration

Log4j Scala API uses Log4j configuration by default. This supports XML, properties files, and Java-based builders, as well as JSON and YAML with additional dependencies.

Substituting Parameters

Unlike in Java, Scala provides native functionality for string interpolation beginning in Scala 2.10. As all logger calls are implemented as macros, using string interpolation directly does not require additional if checks. For example:

logger.debug(s"Logging in user ${user.getName} with birthday ${user.calcBirthday}")

Logger Names

Most logging implementations use a hierarchical scheme for matching logger names with logging configuration. In this scheme the logger name hierarchy is represented by '.' characters in the logger name, in a fashion very similar to the hierarchy used for Java/Scala package names. The Logger property added by the Logging trait follows this convention: the trait ensures the Logger is automatically named according to the class it is being used in.

Download

Apache Log4j Scala API is distributed under the Apache License, version 2.0. The link in the Mirrors column should display a list of available mirrors with a default selection based on your inferred location. If you do not see that page, try a different browser. The checksum and signature are links to the originals on the main distribution server.

Distribution Mirrors Signature SHA-256 SHA-512

Apache Log4j Scala API binary (tar.gz)

apache-log4j-api-scala-12.0-bin.tar.gz

apache-log4j-api-scala-12.0-bin.tar.gz.asc

apache-log4j-api-scala-12.0-bin.tar.gz.sha256

apache-log4j-api-scala-12.0-bin.tar.gz.sha512

Apache Log4j Scala API binary (zip)

apache-log4j-api-scala-12.0-bin.zip

apache-log4j-api-scala-12.0-bin.zip.asc

apache-log4j-api-scala-12.0-bin.zip.sha256

apache-log4j-api-scala-12.0-bin.zip.sha512

Apache Log4j Scala API source (tar.gz)

apache-log4j-api-scala-12.0-src.tar.gz

apache-log4j-api-scala-12.0-src.tar.gz.asc

apache-log4j-api-scala-12.0-src.tar.gz.sha256

apache-log4j-api-scala-12.0-src.tar.gz.sha512

Apache Log4j Scala API source (zip)

apache-log4j-api-scala-12.0-src.zip

apache-log4j-api-scala-12.0-src.zip.asc

apache-log4j-api-scala-12.0-src.zip.sha256

apache-log4j-api-scala-12.0-src.zip.sha512

It is essential that you verify the integrity of the downloaded files using the PGP signatures or the SHA-2 checksum files (SHA-256 or SHA-512). Please read Verifying Apache HTTP Server Releases for more information on why you should verify our releases.

The PGP signatures can be verified using PGP or GPG. First download the KEYS as well as the asc signature file for the relevant distribution. Make sure you get these files from the main distribution directory, rather than from a mirror. Then verify the signatures using:

gpg --import KEYS
gpg --verify apache-log4j-api-scala-12.0-bin.tar.gz.asc apache-log4j-api-scala-12.0-bin.tar.gz
gpg --verify apache-log4j-api-scala-12.0-bin.zip.asc apache-log4j-api-scala-12.0-bin.zip
gpg --verify apache-log4j-api-scala-12.0-src.tar.gz.asc apache-log4j-api-scala-12.0-src.tar.gz
gpg --verify apache-log4j-api-scala-12.0-src.zip.asc apache-log4j-api-scala-12.0-src.zip

Log4j Scala API requires Log4j API.

Using SBT

How to add Log4j Scala API to your project using Log4j 2:

build.sbt
libraryDependencies ++= Seq(
  "org.apache.logging.log4j" %% "log4j-api-scala" % "12.0",
  "org.apache.logging.log4j" % "log4j-core" % "2.13.0" % Runtime
)

ChangeLog

Version 12.0

New Features
LOG4J2-1882

Migrate log4j-api-scala to sbt.

LOG4J2-2303

Add release distribution script.

LOG4J2-2295

Add OSGi metadata to release jars.

LOG4J2-2294

Add release audit information to build.

LOG4J2-2298

Add changelog to site.

LOG4J2-2293

Add required license files to sbt output artifacts.

LOG4J2-2296

Add sbt-site plugin and website configuration.

LOG4J2-2291

Add Jenkins pipeline for sbt build.

LOG4J2-2668

Add support for Scala 2.13.

Bug Fixes

None.

Changes
LOG4J2-2309

Update Log4j Scala API for 2.13 from 2.13.0-M2 to 2.13.0-M3.

LOG4J2-2290

Update Log4j from 2.9.1 to 2.13.2.

LOG4J2-1995

Update log4j-api-scala_2.11 from Scala 2.11.8 to 2.11.11.

LOG4J2-1996

Update log4j-api-scala_2.12 from Scala 2.12.1 to 2.12.3.

LOG4J2-2115

Update Log4j dependency from 2.8.1 to 2.9.1.

LOG4J2-2116

Update log4j-api-scala_2.12 from Scala 2.12.3 to 2.12.4.

Removed

None.

Building From Source

Note
The following information is for developers who wish to modify Log4j Scala API or contribute. If your goal is to add logging to your application, then you can use the pre-built binaries instead.
Auditing
./sbt auditCheck
Building
./sbt "+ package"

Contributing

You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to the open source community. Before you dig right into the code there are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

Getting Started

  • Make sure you have a Jira account.

  • Make sure you have a GitHub account.

  • If you’re planning to implement a new feature it makes sense to discuss your changes on the dev list first. This way you can make sure you’re not wasting your time on something that isn’t considered to be in Apache Log4j’s scope.

  • Submit a ticket for your issue, assuming one does not already exist.

  • Clearly describe the issue including steps to reproduce when it is a bug.

  • Make sure you fill in the earliest version that you know has the issue.

  • Fork the repository on GitHub.

Making Changes

  • Create a topic branch from where you want to base your work (this is usually the master branch).

  • Make commits of logical units.

  • Respect the original code style:

  • Only use spaces for indentation.

  • Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.

  • Check for unnecessary whitespace with git diff --check before committing.

  • Make sure your commit messages are in the proper format. Your commit message should contain the key of the Jira issue.

  • Make sure you have added the necessary tests for your changes.

  • Run all the tests with sbt "+ test" to assure nothing else was accidentally broken.

Making Trivial Changes

For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number.

Submitting Changes

  • Sign the Contributor License Agreement if you haven’t already.

  • Push your changes to a topic branch in your fork of the repository.

  • Submit a pull request to the repository in the apache organization.

  • Update your Jira ticket and include a link to the pull request in the ticket.

Release Audit Report

Generated at: 2020-05-03T11:24:27-05:00

Summary

  • Notes: 0

  • Binaries: 0

  • Archives: 0

  • Standards: 4

  • Apache Licensed: 4

  • Generated Documents: 0

    • JavaDocs are generated, thus a license header is optional. Generated files do not require license headers.

  • Unknown Licenses: 0

Files

Files with Apache License headers will be marked AL. Binary files (which do not require any license headers) will be marked B. Compressed archives will be marked A. Notices, licenses etc. will be marked N.

OK? Type File

AL

/Users/matt/code/logging/scala/src/main/scala/org/apache/logging/log4j/scala/Logging.scala

AL

/Users/matt/code/logging/scala/src/main/scala/org/apache/logging/log4j/scala/Logger.scala

AL

/Users/matt/code/logging/scala/src/main/scala-2.11+/org/apache/logging/log4j/scala/LoggerMacro.scala

AL

/Users/matt/code/logging/scala/src/main/scala-2.13+/org/apache/logging/log4j/scala/LoggingContext.scala