Coder Social home page Coder Social logo

akka-logback's Introduction

akka-logback

Build Status Maven Central Scala Steward badge

akka-logback helps integrate logback with your Akka 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.

libraryDependencies += "com.armanbilge" %% "akka-logback" % "0.1.1" % Runtime

Usage

Enable akka-logback in your application.conf.

# 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 from your Akka configuration.

<configuration>
    <!-- Sets the variable `AKKA_LOGLEVEL` to the value of the `akka.loglevel` setting defined in the Akka configuration -->
    <akkaProperty name="AKKA_LOGLEVEL" path="akka.loglevel" />

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Sets the root logger level to the value of the `AKKA_LOGLEVEL` variable via substitution -->
    <root level="${AKKA_LOGLEVEL}">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

See the Akka documentation 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.

def setActorSystem(actorSystem: akka.actor.ActorSystem): Unit

For an example of this, see the Google Cloud Logging Appender.

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.

akka-logback's People

Contributors

armanbilge avatar scala-steward avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.