Dynamic Log Levels
Dynamic Log Levels for Logback 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 | |
---|---|
Artifact | com.lightbend.akka.management
akka-management-loglevels-logback
1.0.10
|
JDK versions | Adopt OpenJDK 8 with Hotspot Adopt OpenJDK 11 with Hotspot |
Scala versions | 2.11.12, 2.12.13, 2.13.5 |
License | |
Readiness level | Supported, Lightbend Subscription provides support
Since 0.16.0, 2019-11-29
|
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 Logback as logging backend.
- sbt
val AkkaManagementVersion = "1.0.10" libraryDependencies ++= Seq( "com.lightbend.akka.management" %% "akka-management-loglevels-logback" % AkkaManagementVersion, "com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion )
- Gradle
def versions = [ AkkaManagementVersion: "1.0.10", ScalaBinary: "2.12" ] dependencies { implementation "com.lightbend.akka.management:akka-management-loglevels-logback_${versions.ScalaBinary}:${versions.AkkaManagementVersion}" implementation "com.lightbend.akka.management:akka-management_${versions.ScalaBinary}:${versions.AkkaManagementVersion}" }
- Maven
<properties> <akka.management.version>1.0.10</akka.management.version> <scala.binary.version>2.12</scala.binary.version> </properties> <dependencies> <dependency> <groupId>com.lightbend.akka.management</groupId> <artifactId>akka-management-loglevels-logback_${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-logback
can be used with Akka 2.5.31 or 2.6.9 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.6.9 can be used.
- sbt
val AkkaVersion = "2.6.9" libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-stream" % AkkaVersion, "com.typesafe.akka" %% "akka-slf4j" % AkkaVersion )
- Gradle
def versions = [ AkkaVersion: "2.6.9", ScalaBinary: "2.12" ] 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.6.9</akka.version> <scala.binary.version>2.12</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/logback?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/logback?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/logback?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"