StackHub Home

Log analytics as a service

Sign Up | Log In | Guides

Configuring your Logback application to use StackHub

This tutorial assumes you already have the StackHub daemon up and running with your application token. If you don't have the daemon installed yet, do that first.

1. Specify an appender

Let's say your existing application prints logging events of level INFO and above to stdout using a simple console appender like this:

# Simple logback.xml file
<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <appender name="dest" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d [%t] %-5p %c - %m%n</Pattern>
    </layout>
  </appender>
  <root level="INFO">
    <appender-ref ref="dest"/>
  </root>
</configuration>
Make sure your application is happily logging to console before proceeding.

We are going to keep your existing Logback configuration the way it is, and just add a new SocketAppender to the mix. The SocketAppender will connect to the StackHub daemon when your application starts up.

# A logback.xml file using a SocketAppender to connect with the StackHub daemon
<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <appender name="dest" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d [%t] %-5p %c - %m%n</Pattern>
    </layout>
  </appender>
  <appender name="stackhub" class="ch.qos.logback.classic.net.SocketAppender">
    <Port>8888</Port>
    <RemoteHost>10.0.1.2</RemoteHost>
    <ReconnectionDelay>5</ReconnectionDelay>
    <IncludeCallerData>false</IncludeCallerData>
  </appender>
  <root level="INFO">
    <appender-ref ref="dest"/>
    <appender-ref ref="stackhub"/>
  </root>
</configuration>

You'll need to change RemoteHost to whatever IP address your daemon says it is listening on.

2. Restart your app to reload the Logback configuration

3. Verify that it's working

In your StackHub daemon output, you should see something like this:

INFO  stackhub.LoggingReceiver  - Starting new socket node with remote client at 10.0.1.17

In the example above, both appenders are logging the same things. So if you don't see anything logged in stdout, you won't see anything at StackHub either!

Continue