Java Logback Using HTTP/S

You can send your Java logs using our Logback extension. It sends directly from your application to Loggly using the HTTP/S Event API. We automatically parse out the timestamp, method, fully classified class name, thread, and log level from these log lines. It also allows you to send properly formatted multiline stacktraces. Please note that the HTTP protocol has a data rate that is limited by your latency to our log collector. This guide uses logback-ext-loggly version 0.1.2 or higher, and the default Logback configuration. For alternatives, please see the Advanced Options section.

Java Logback Setup

  1. Add Logback Extension
  2. Add a dependency for the Loggly Logback extension from the Maven repository or from GitHub. The Maven repository has code snippets to add the dependencies for many common package managers.

    For example, if you are using Maven, then add this to the dependencies section of your pom.xml file.

    <dependency>
        <groupId>org.logback-extensions</groupId>
        <artifactId>logback-ext-loggly</artifactId>
        <version>0.1.2</version>
    </dependency>
    

    Then run maven to install the extension

    mvn clean install
    

  3. Configure Logback
  4. Open or create your logback.xml configuration file and add the LogglyAppender. The following pattern will parse the log as Java log in Loggly and it also parses the objects in JSON format and string in the plain text format.

    <configuration debug="true">
       <appender name="loggly" class="ch.qos.logback.ext.loggly.LogglyAppender">
           <endpointUrl>https://logs-01.loggly.com/inputs/TOKEN/tag/logback</endpointUrl>
           <pattern>%d{"ISO8601", UTC}  %p %t %c %M - %m%n</pattern>
       </appender>
       <root level="info">
           <appender-ref ref="loggly" />
       </root>
    </configuration>
    

    Replace:

  5. Add Logging Code
  6. Add code to construct a SLF4J Logger and then send a test event.

    import org.slf4j.*;
    final static Logger logger = LoggerFactory.getLogger();
    logger.info("Hello World from Logback!");
    logger.info("{\"message" : \"Hello World from Logback!\"}");
    

  7. Send Test Events
  8. Run your application to send test events to Loggly.

  9. Verify Events
  10. Search Loggly for events with tag as Logback over the past 20 minutes. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

    tag:logback

    Click on one of the logs to show a list of Java or JSON fields (see screenshot below). If you don’t see them, please check that you are using one of our automatically parsed formats.
    java_logback

  11. Next Steps

Advanced Java Logback Options

  • Java Logback Using Syslog – send logs using the syslog protocol for nonblocking and higher data rate applications
  • Java Log4j – Send Log4j logs over syslog if you prefer local centralized management
  • HTTP/S Bulk Endpoint – Send up to 5MB batches of logs over HTTP/S for higher performance
  • Log File Monitoring – You can also configure Log4j with a FileAppender, then monitor that file using Rsyslog. This gives you a local backup.
  • Loggly Libraries Catalog – There are libraries available for Log4j over HTTP if you don’t have system level access, as well as SLF4j
  • Search or post your own Java Logback or Java logging questions in the community forum.

Troubleshooting Java Logging

If you don’t see any data show up in the verification step, then check for these common problems.

    Check Logback:

  • Wait a few minutes in case indexing needs to catch up.
  • Verify Logback is working, such as by setting up a local file appender with the same format.
  • See our HTTP Troubleshooting Guide to verify HTTP events are being sent to Loggly.
  • Still Not Working?

  • Search or post your own question in the community forum.
Thanks for the feedback! We'll use it to improve our support documentation.


Top