Documentation forLoggly

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

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 

2. Logback Configuration

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:

3. Add Logging Code

Add code to construct an SLF4J Logger and then send a test event.

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

Replace:

  • ClassName: your java application class name

4. Send Test Events

Run your application to send test events to Loggly.

5. Verify Events

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 Using HTTP/S Example

6. 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
  • Programmatic Configuration – You can set Loggly’s configurations, like loggly_collector, logging_mode, customer_token, tags, etc., programmatically without creating a separate XML configuration file. Please see a working sample project here to achieve this.
  • 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?

When the APM Integrated Experience is enabled, Loggly shares a common navigation and settings with the other integrated experiences' products. How you navigate Loggly and access its features may vary from these instructions. For more information, go to the APM Integrated Experience documentation.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.