https://github.com/armanbilge/akka-logback
Integrate logback with your Akka application
https://github.com/armanbilge/akka-logback
akka logback logging slf4j
Last synced: 6 months ago
JSON representation
Integrate logback with your Akka application
- Host: GitHub
- URL: https://github.com/armanbilge/akka-logback
- Owner: armanbilge
- License: apache-2.0
- Archived: true
- Created: 2021-04-09T05:57:46.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-29T02:33:32.000Z (over 4 years ago)
- Last Synced: 2024-05-02T05:54:19.120Z (about 2 years ago)
- Topics: akka, logback, logging, slf4j
- Language: Scala
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# akka-logback

[](https://maven-badges.herokuapp.com/maven-central/com.armanbilge/akka-logback_2.13)
[](https://scala-steward.org)
akka-logback helps integrate [logback](https://logback.qos.ch/) with your [Akka](https://akka.io) applications.
Features:
* Allows logback properties to be sourced from the Akka configuration
* Provides logback appenders access to the actor system
## Installation
The artifact is published to Maven Central.
```scala
libraryDependencies += "com.armanbilge" %% "akka-logback" % "0.1.1" % Runtime
```
## Usage
Enable akka-logback in your `application.conf`.
```hocon
# AkkaLogback must be initialized before Slf4jLogger
akka.loggers = ["com.armanbilge.akkalogback.AkkaLogback", "akka.event.slf4j.Slf4jLogger"]
```
Your logback configuration is then automatically loaded from one of the following locations, ranked by priority.
1. The path specified by the `akka-logback.configuration-file` setting in your `application.conf`
2. `logback-akka-test.xml` in the class path
3. `logback-akka.xml` in the class path
Note that if `logback.xml`, `logback-test.xml`, or `logback.groovy` are on the class path or the system property `logback.configurationFile` is set, then akka-logback will be bypassed and logback will initialize normally (i.e., without the Akka extensions).
Configuration via Groovy is not supported at this time.
Now you can source [logback properties](https://logback.qos.ch/manual/configuration.html#variableSubstitution) from your Akka configuration.
```xml
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
```
See the [Akka documentation](https://doc.akka.io/docs/akka/current/typed/logging.html#logback) for guidance on configuring logback.
**Caveat**: logging now depends on your actor system, so creating an actor system should be one of the first things that your app does (specifically, before obtaining a logger via SLF4J).
### Implementing Akka-based appenders
To implement a logback appender that has access to the `ActorSystem`, add a setter method to your appender with the following signature.
akka-logback will use it to provide the `ActorSystem` to your appender during initialization before its `start()` method is invoked.
```scala
def setActorSystem(actorSystem: akka.actor.ActorSystem): Unit
```
For an example of this, see the [Google Cloud Logging Appender](https://github.com/armanbilge/alpakka/blob/google-cloud-logging/google-cloud-logging/src/main/scala/akka/stream/alpakka/googlecloud/logging/logback/CloudLoggingAppender.scala).
## Contribution policy
Contributions via GitHub pull requests are gladly accepted from their original author.
Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license.
Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.
## License
This code is open source software licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).