Skip to main content
OpenTelemetry Java uses log appenders to intercept log messages from popular logging frameworks and convert them into OTLP logs. Log appenders work with both the OpenTelemetry Java agent and the OpenTelemetry Java SDK. The following example shows how to configure a Java application using Gradle to send Log4j logs to Honeycomb or an OpenTelemetry Collector.
1

Acquire Dependencies

Install the OpenTelemetry Java agent. The Log4j appender is bundled with the agent and installs automatically.
2

Install the Log Appender

The Log4j appender is bundled with the agent and requires no additional configuration.
3

Configure Log4j

Configure Log4j using a configuration file. The following example logs all messages to both the console and the OpenTelemetry log appender.The packages property on the top-level Configuration element tells Log4j to scan for custom appenders in the package. The OpenTelemetry appender is defined in Appenders and referenced in the root logger (Loggers > Root).
Then, in your application code you can use Log4j’s LogManager to create loggers and emit log messages:
4

Run Your Application

Create an otelconfig.yaml file and point the agent at it using OTEL_CONFIG_FILE.
When OTEL_CONFIG_FILE is set, the configuration file is the single source of truth for the SDK. Other OTEL_* environment variables are ignored by design, so set all SDK options in the YAML file. You can still reference environment variables from inside the YAML using ${VAR_NAME} substitution.
To send logs directly to Honeycomb:
To send logs to an OpenTelemetry Collector instead:

Available Log Appenders

OpenTelemetry Java includes log appenders for popular logging frameworks. Each appender intercepts log messages and routes them through the OpenTelemetry export pipeline. Available log appenders include: