Dash0 Java Logback integration provides efficient log collection with minimal overhead using OpenTelemetry Logback Appender.
Logback is one of the most widely used logging frameworks for Java applications. It was designed as a successor to the popular Log4j project and natively implements the SLF4J API, making it both powerful and flexible for various logging needs.
Logback can be configured to export logs directly through the OpenTelemetry protocol using the OpenTelemetry Logback Appender. This approach ensures your logs are properly correlated with traces and metrics in Dash0.
First, add the OpenTelemetry Logback Appender dependency to your project.
Maven:
Gradle:
Next, update your logback.xml
configuration file to include the OpenTelemetry appender:
The OpenTelemetry appender supports several configuration options:
captureExperimentalAttributes
: Captures experimental attributes like thread.name
.captureCodeAttributes
: Captures code location attributes (file, line number)captureMarkerAttribute
: Captures SLF4J marker attributescaptureKeyValuePairAttributes
: Captures key-value pairs from structured loggingcaptureLoggerContext
: Captures the logger contextcaptureMdcAttributes
: Captures MDC (Mapped Diagnostic Context) attributes using the specified patternFinally, make the appender aware of your OpenTelemetry SDK instance as early as possible in your application's startup sequence:
Logback's MDC provides a way to enrich log events with additional contextual information. The OpenTelemetry appender can capture these MDC values as attributes on your log records:
With this configuration, your logs will be sent to Dash0 via OpenTelemetry, properly correlated with your traces and metrics, providing you with a unified view of your application's behavior.