malliina / logback-rx

Logback to Observable

Version Matrix

Build Status Maven Central


This library provides Rx Observables for events logged using Logback. You might find this useful if you wish to stream log events to your user interface with minimal delay.


"com.malliina" %% "logback-rx" % "1.3.0"


Log events are pushed to Observables using custom Logback appenders. The PublishRxAppender provides an Observable that emits any events subsequent to a subscription. The BoundedReplayRxAppender emits a history of log events and any following events. The bufferSize property controls the maximum number of log events to replay.


Add a custom Logback appender to your Logback configuration, then obtain it in code to access the Observable of log events.

Here's an example logback.xml:

    <appender name="RX" class="com.mle.logbackrx.BasicPublishRxAppender"/>
    <appender name="BOUNDED" class="com.mle.logbackrx.BasicBoundedReplayRxAppender">
        <timeFormat>yyyy:MM:dd HH:mm:ss</timeFormat>
    <root level="INFO">
        <appender-ref ref="RX"/>
        <appender-ref ref="BOUNDED"/>

To customize time formatting, use the timeFormat property of the appenders, which works according to the SimpleDateFormat time syntax.

In order to access the Observable of log events, you need to get the appender first:

// gets appender based on name from logback.xml
val appender = com.mle.logbackrx.LogbackUtils.getAppender[BasicPublishRxAppender]("RX")
// subscribes to observable of log events
val subscription = appender.logEvents.subscribe(event => println(event))

You could also have installed the appender programmatically:

val appender = new BasicBoundedReplayRxAppender
appender.logEvents.subscribe(e => println(e))

Events you log using the SLF4J API with Logback will now be emitted by the Observable:"Hello, world")