Skip to content
Logback Java appender for LogDNA.com
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
pom.xml

README.md

LogDNA Logback appender

This library provides an appender for logback, allowing to send your logs to the LogDNA online logging platform, via their HTTPS Ingest API. MDC thread-bound data can be send, indexed and searched into your LogDNA dashboard.

How to use it

First, copy this dependency into your pom.xml file.

<dependency>
    <groupId>net.zileo</groupId>
    <artifactId>logback-logdna</artifactId>
    <version>1.0.1</version>
</dependency>

Note that this library relies on Jersey JAX-RS implementation with Jackson JSON mapper. For a lightweight implementation, you can check this other appender.

Copy the following two LogDna appenders to your classpath:/logback.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="LogDnaHttp" class="net.zileo.logback.logdna.LogDnaAppender">
        <encoder>
            <pattern>[%thread] %msg%n</pattern>
        </encoder>
        <appName>YouApplicationName</appName>
        <ingestKey>${LOGDNA_INGEST_KEY}</ingestKey>
        <ingestUrl>${LOGDNA_INGEST_URL}</ingestUrl>
        <mdcFields>field1,field2</mdcFields>
        <mdcTypes>string,int</mdcTypes>
        <tags>dev</tags>
    </appender>
    
    <appender name="LogDna" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="LogDnaHttp" />
        <queueSize>500</queueSize>
        <discardingThreshold>50</discardingThreshold>
        <includeCallerData>false</includeCallerData>
        <neverBlock>true</neverBlock>
    </appender>

    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm} %-5level %msg%n</pattern>
        </encoder>
    </appender>
    
    <root level="INFO">
        <appender-ref ref="Console" />
        <appender-ref ref="LogDna" />
    </root>
    
</configuration>

This configuration is based on an asynchronous wrapper, for performance reason. Check this nice OverOps blog article for more info.

Configuration options

  • You can use your own pattern.
  • Set up your LOGDNA_INGEST_KEY (api key) via the System properties.
  • Set up the LOGDNA_INGEST_URL (api url) the same way. (Should be https://logs.logdna.com/logs/ingest)
  • Set up comma-separated tags if you want to.
  • Set up comma-separated MDC keys to index (from the MDC thread local binding).
  • Set up one type for each MDC key.

Possible types are string, boolean, int and long. The last two result in an indexed number in your LogDNA console, which is rather interesting, as it will allow you some functions inside your graphs (sum, average, etc...).


Proudly provided by Zileo.net

You can’t perform that action at this time.