Log4j2
Dynamic Log Levels for Log4j2 hooks into Akka Management and provides a route where log levels can be read and set over HTTP.
Project Info
Project Info: Dynamic Log Levels Log4j 2 | |
---|---|
Artifact | com.lightbend.akka.management
akka-management-loglevels-log4j2
1.6.0
|
JDK versions | Eclipse Temurin JDK 11 Eclipse Temurin JDK 17 Eclipse Temurin JDK 21 |
Scala versions | 2.13.15, 3.3.4 |
License | |
Readiness level |
Since 1.1.1, 2021-11-18
|
Home page | https://akka.io/ |
API documentation | |
Forums | |
Release notes | GitHub releases |
Issues | GitHub issues |
Sources | https://github.com/akka/akka-management |
Requires Akka Management and that the application uses Log4j2 as logging backend.
The Akka dependencies are available from Akka’s library repository. To access them there, you need to configure the URL for this repository.
- sbt
resolvers += "Akka library repository".at("https://repo.akka.io/maven")
- Gradle
repositories { mavenCentral() maven { url "https://repo.akka.io/maven" } }
- Maven
<project> ... <repositories> <repository> <id>akka-repository</id> <name>Akka library repository</name> <url>https://repo.akka.io/maven</url> </repository> </repositories> </project>
Additionally, add the dependencies as below.
- sbt
val AkkaManagementVersion = "1.6.0" libraryDependencies ++= Seq( "com.lightbend.akka.management" %% "akka-management-loglevels-log4j2" % AkkaManagementVersion, "com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion )
- Gradle
def versions = [ AkkaManagementVersion: "1.6.0", ScalaBinary: "2.13" ] dependencies { implementation "com.lightbend.akka.management:akka-management-loglevels-log4j2_${versions.ScalaBinary}:${versions.AkkaManagementVersion}" implementation "com.lightbend.akka.management:akka-management_${versions.ScalaBinary}:${versions.AkkaManagementVersion}" }
- Maven
<properties> <akka.management.version>1.6.0</akka.management.version> <scala.binary.version>2.13</scala.binary.version> </properties> <dependencies> <dependency> <groupId>com.lightbend.akka.management</groupId> <artifactId>akka-management-loglevels-log4j2_${scala.binary.version}</artifactId> <version>${akka.management.version}</version> </dependency> <dependency> <groupId>com.lightbend.akka.management</groupId> <artifactId>akka-management_${scala.binary.version}</artifactId> <version>${akka.management.version}</version> </dependency> </dependencies>
Akka Management and akka-management-loglevels-log4j2
can be used with Akka 2.10.0 or later. You have to override the following Akka dependencies by defining them explicitly in your build and define the Akka version to the one that you are using. Latest patch version of Akka is recommended and a later version than 2.10.0 can be used.
- sbt
val AkkaVersion = "2.10.0" libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-stream" % AkkaVersion, "com.typesafe.akka" %% "akka-slf4j" % AkkaVersion )
- Gradle
def versions = [ AkkaVersion: "2.10.0", ScalaBinary: "2.13" ] dependencies { implementation "com.typesafe.akka:akka-stream_${versions.ScalaBinary}:${versions.AkkaVersion}" implementation "com.typesafe.akka:akka-slf4j_${versions.ScalaBinary}:${versions.AkkaVersion}" }
- Maven
<properties> <akka.version>2.10.0</akka.version> <scala.binary.version>2.13</scala.binary.version> </properties> <dependencies> <dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-stream_${scala.binary.version}</artifactId> <version>${akka.version}</version> </dependency> <dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-slf4j_${scala.binary.version}</artifactId> <version>${akka.version}</version> </dependency> </dependencies>
With Akka Management started and this module on the classpath the module is automatically picked up and provides the following two HTTP routes:
Reading Logger Levels
A HTTP GET
request to loglevel/log4j2?logger=[logger name]
will return the log level of that logger.
Changing Logger Levels
Only enabled if akka.management.http.route-providers-read-only
is set to false
.
If enabling this make sure to properly secure your endpoint with HTTPS and authentication or else anyone with access to the system could change logger levels and potentially do a DoS attack by setting all loggers to TRACE
.
A HTTP PUT
request to loglevel/log4j2?logger=[logger name]&level=[level name]
will change the level of that logger on the JVM the ActorSystem
runs on.
For example using curl:
curl -X PUT "http://127.0.0.1:8558/loglevel/log4j2?logger=com.example.MyActor&level=DEBUG"
Classic and Internal Akka Logger Level
Internal Akka actors and classic Akka does logging through the built in API there is an additional level of filtering using the akka.loglevel
setting. If you have not set akka.loglevel
to DEBUG
(recommended) log entries from the classic logging API may never reach the logger backend at all.
The current level configured with akka.loglevel
can be inspected with a GET request to loglevel/akka
.
If management read-only
is set to false
PUT requests to loglevel/akka?level=[level name]
will dynamically change that. Note that the allowed level for Akka Classic logging is a subset of the loglevels supported by SLF4j, valid values are OFF
, DEBUG
, INFO
, WARNING
and ERROR
.
For example using curl:
curl -X PUT "http://127.0.0.1:8558/loglevel/akka?level=DEBUG"