---
title: "Log4j 2 Integration"
description: "Learn how to use Sentry's Log4j 2 integration with Spring Boot."
url: https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2/
---

# Log4j 2 Integration | Sentry for Spring Boot

For the best experience, we recommend using Sentry's Spring Boot integration with the Log4j 2 logging framework integration as they work together seamlessly.

##### Logs over Breadcrumbs

By default this integration captures logs as breadcrumbs and error events (great for error context!). But if you need to search and query your logs across your entire application, we recommend enabling the new logs feature. Logs at or above the `minimumLevel` are automatically sent as Sentry Logs when enabled.

## [Installation](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md#installation)

To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module:

```xml
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-log4j2</artifactId>
    <version>8.37.1</version>
</dependency>
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-log4j2).

## [Configuration](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md#configuration)

### [Spring Boot Configuration](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md#spring-boot-configuration)

To send logs to Sentry and have them show up in the Logs section, you need to enable the feature:

```properties
sentry.logs.enabled=true
```

### [XML Configuration](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md#xml-configuration)

[Follow the guide on configuring Log4j 2 with Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-log4j-for-logging) and configure `SentryAppender` in the `log4j2.xml` file:

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

  <Appenders>
    <Console name="CONSOLE" target="SYSTEM_OUT">
      <PatternLayout
        pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
      />
    </Console>
    <Sentry name="SENTRY" minimumLevel="DEBUG" />
  </Appenders>

  <Loggers>
    <Root level="INFO">
      <AppenderRef ref="CONSOLE" />
      <AppenderRef ref="SENTRY" />
    </Root>
  </Loggers>

</Configuration>
```

You do not need to configure your DSN in the Log4j 2 configuration file since Sentry is configured from the Spring Boot integration.

However, if errors that may appear during startup should to be sent to Sentry, the DSN must be provided to *both* the Log4j 2 and Spring Boot configurations.

## [Mapped Diagnostic Context (MDC)](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md#mapped-diagnostic-context-mdc)

Starting with Sentry Java SDK version 8.24.0, you can use the [`contextTags`](https://docs.sentry.io/platforms/java/guides/spring-boot/configuration/options.md#contextTags) option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.
