Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ By default this integration captures logs as breadcrumbs and error events (great

## Installation

To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module:
Spring Boot uses Logback by default, so first [follow the guide on configuring Log4j 2 with Spring Boot](https://docs.spring.io/spring-boot/how-to/logging.html#howto.logging.log4j) to make Log4j 2 the active logging backend.

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

```xml {tabTitle:Maven}
<dependency>
Expand Down Expand Up @@ -43,9 +45,40 @@ To send logs to Sentry and have them show up in the Logs section, you need to en
sentry.logs.enabled=true
```

For Spring Boot 3 and 4, Sentry can register `SentryAppender` for you once the application context refreshes. This auto-configuration is opt-in:

```properties
sentry.logging.enabled=true
```

If Log4j 2 isn't the active logging backend, the appender isn't added.

Minimum logging levels for `SentryAppender` can be configured in `application.properties` or `application.yml` file.

```properties
sentry.logging.minimum-event-level=info
sentry.logging.minimum-breadcrumb-level=debug
sentry.logging.minimum-level=debug
```

The default values are:

- `info` or higher to include a log message as breadcrumb.
- `info` or higher will send a log message to Sentry and will show up in the Logs section.
- `error` or higher will send an event to Sentry and will show up in the Issues section.

The appender is added to the root logger by default. To attach it to specific loggers instead, configure their names:

```properties
sentry.logging.loggers[0]=com.example.orders
sentry.logging.loggers[1]=com.example.payments
```

Use non-overlapping logger names. Log4j 2 loggers are additive by default, so attaching the appender to both a logger and one of its ancestors can send the same log entry twice.

### 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:
Spring Boot 2 doesn't support `SentryAppender` auto-configuration, and errors logged before the Spring context refreshes aren't captured by it. In both cases, leave `sentry.logging.enabled` unset and configure `SentryAppender` in the `log4j2.xml` file:

```xml
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
Loading