Log4j Scala API provides a Scala-friendly interface to log against the Log4j API.
It supports Scala 2.10
, 2.11
, 2.12
, 2.13
, and 3
.
This is just a logging API. Your application still needs to have a logging backend (e.g., Log4j) configured. |
Dependencies
You need to have the org.apache.logging.log4j:log4j-api-scala
dependency in your classpath:
libraryDependencies ++= Seq(
"org.apache.logging.log4j" %% "log4j-api-scala" % "13.1.0"
)
Java module name is set to org.apache.logging.log4j.api.scala
.
OSGi Bundle-SymbolicName
s are set to org.apache.logging.log4j.api.scala.2.10
, org.apache.logging.log4j.api.scala.2.11
, and so on.
Usage
Using the Scala API is as simple as mixing in the Logging
trait to your class:
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}.")
}
}
Parameter substitution
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:
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.
Development
Log4j Scala API uses GitHub for source code management.
The project requires two Java compilers to build:
-
8
(required for Scala2.10
and2.11
) -
one matching the
[17,18)
range.
You can build and verify sources using:
./mvnw verify
You can build and view the website as follows:
./mvnw -N site
python -m http.server -d target/site
Distribution
In accordance with the Apache Software Foundation’s release distribution policy and creation process, project artifacts are officially accessible from the following locations:
-
ASF Release and snapshot repositories (mirrored to the Maven Central Repository)
See the release instructions for details.
CycloneDX Software Bill of Materials (SBOM)
Starting with version 13.1.0
, Log4j Scala API distributes CyclenoDX Software Bill of Materials (SBOM) along with each deployed artifact.
This is streamlined by logging-parent
, see its website for details.
Support
Please keep in mind that this project is intended for internal usage only. You can use GitHub Issues for feature requests and bug reports – not questions! See the Log4j support policy for details.
Security
If you have encountered an unlisted security vulnerability or other unexpected behaviour that has security impact, please report them privately to the Log4j security mailing list. See the Log4j Security page for further details.
Release Notes
13.1.0
- Release date
-
2024-02-01
This minor release contains a bug fix, Software Bill of Materials (SBOM) generation, and some dependency updates.
Added
-
Start generating CycloneDX SBOM
Fixed
-
Fix recursive inlining issues in Scala 3 macros (40)
13.0.0
- Release date
-
2023-10-10
The highlights of this major release are Scala 3 support, OSGi and JPMS descriptors, and the switch to semantic versioning.
Note that this release is still binary backward compatible with the earlier release 12.0
.
Though we needed to bump the major version number for the semantic versioning switch to avoid the confusion related with version ordering.
Added
-
Add support for Scala 3 (LOG4J2-3184, 26)
-
Add OSGi and JPMS support
Changed
-
Bump the Java version to 17 (Scala 2.10 and 2.11 targets still require Java 8 that build switches to using
maven-toolchains-plugin
) -
Switch the CI to GitHub Actions
-
Switch from
sbt
to Maven to take advantage oflogging-parent
conveniences -
Switch to semantic versioning
-
Update
org.apache.logging.log4j:log4j-api
version to2.20.0
-
Update
org.apache.logging:logging-parent
to version10.1.1
-
Start using
log4j-changelog
12.0
- Release date
-
2020-05-03
This is the first release of the project.
Added
-
Add Jenkins pipeline for
sbt
build (LOG4J2-2291) -
Add required license files to
sbt
output artifacts (LOG4J2-2293) -
Add
apache-rat-plugin
reports (LOG4J2-2294) -
Add OSGi descriptors (LOG4J2-2295)
-
Add
sbt-site
plugin and website configuration (LOG4J2-2296) -
Add changelog to site (LOG4J2-2298)
-
Add support for Scala 2.13 (LOG4J2-2668)
Changed
-
Switch from
sbt
to Maven to take advantage oflogging-parent
conveniences (LOG4J2-1882) -
Add release distribution script (LOG4J2-2303)
Release instructions
Log4j Scala API employs the CI/CD foundation provided by the logging-parent
.
You can simply use its release instructions.
License
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
See NOTICE.txt
distributed with this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.