Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,11 @@
---
title: Logging Framework Integrations
sidebar_order: 6
description: "Learn more about using one of our logging integrations with Sentry Spring Boot."
---

## Supported Logging Frameworks

Sentry provides integrations for the following logging frameworks with Spring Boot:

<PageGrid />
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Log4j 2 Integration
description: "Learn how to use Sentry's Log4j 2 integration with 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.

<Alert level="warning" title="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.

</Alert>

## Installation

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

```xml {tabTitle:Maven}
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-log4j2:{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}'
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}"
```

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

## Configuration

### 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

[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>
```

<Alert>

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 <i>both</i> the Log4j 2 and Spring Boot configurations.

</Alert>

## Mapped Diagnostic Context (MDC)

Starting with Sentry Java SDK version 8.24.0, you can use the <PlatformLink to="/configuration/options/#contextTags">`contextTags`</PlatformLink> option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
---
title: Logging Framework Integrations
sidebar_order: 6
description: "Learn more about using one of our logging integrations with Sentry Spring Boot."
title: Logback Integration
description: "Learn how to use Sentry's Logback integration with Spring Boot."
---

For the best experience, we recommend using Sentry's Spring Boot integration with one of the logging framework integrations as they work together seamlessly.
For the best experience, we recommend using Sentry's Spring Boot integration with the Logback logging framework integration as they work together seamlessly.

### Logback
<Alert level="warning" title="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 `sentry.logging.minimum-level` are automatically sent as Sentry Logs when enabled.

</Alert>

## Installation

To use Sentry Logback integration in Spring Boot application you must include a dependency to the `sentry-logback` module, then Sentry's Spring Boot Starter will auto-configure `SentryAppender`:

Expand All @@ -22,6 +27,16 @@ To use Sentry Logback integration in Spring Boot application you must include a
implementation 'io.sentry:sentry-logback:{{@inject packages.version('sentry.java.logback', '4.2.0') }}'
```

## Configuration

### 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
```

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

```properties
Expand All @@ -36,18 +51,14 @@ The default values are:
- `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.

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
```

When `SentryAppender` auto-configuration does not suit your needs, it can be turned off by setting:

```properties
sentry.logging.enabled=false
```

### XML Configuration

If you decide to opt-out from the `application.properties` based Spring Boot logging configuration, and instead configure logging in the `logback-spring.xml` file, the `SentryAppender` can be configured as follows:

```xml
Expand All @@ -56,7 +67,9 @@ If you decide to opt-out from the `application.properties` based Spring Boot log
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />

<appender name="SENTRY" class="io.sentry.logback.SentryAppender" />
<appender name="SENTRY" class="io.sentry.logback.SentryAppender">
<minimumLevel>INFO</minimumLevel>
</appender>

<root>
<appender-ref ref="CONSOLE" />
Expand All @@ -73,63 +86,6 @@ However, if errors that may appear during startup should to be sent to Sentry, t

</Alert>

#### Mapped Diagnostic Context (MDC)

Starting with Sentry Java SDK version 8.24.0, you can use the <PlatformLink to="/configuration/options/#contextTags">`contextTags`</PlatformLink> option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.

### Log4j 2

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

```xml {tabTitle:Maven}
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-log4j2:{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}'
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}"
```

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

Then [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"/>
</Appenders>

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

</Configuration>
```

<Alert>

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 <i>both</i> the Log4j 2 and Spring Boot configurations.

</Alert>

#### Mapped Diagnostic Context (MDC)
## Mapped Diagnostic Context (MDC)

Starting with Sentry Java SDK version 8.24.0, you can use the <PlatformLink to="/configuration/options/#contextTags">`contextTags`</PlatformLink> option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.
7 changes: 7 additions & 0 deletions platform-includes/getting-started-config/java.jul.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ dsn=___PUBLIC_DSN___
# Add data like request headers and IP for users,
# see https://docs.sentry.io/platforms/java/guides/jul/data-management/data-collected/ for more info
send-default-pii=true
<!-- ___PRODUCT_OPTION_START___ logs -->
# Enable logs
logs.enabled=true
<!-- ___PRODUCT_OPTION_END___ logs -->
```
</OnboardingOption>

Expand All @@ -47,6 +51,9 @@ Two log levels are used to configure this integration:

1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry.
2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`).
<OnboardingOption optionId="logs">
3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`).
</OnboardingOption>

<Alert>

Expand Down
18 changes: 16 additions & 2 deletions platform-includes/getting-started-config/java.log4j2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ If the DSN is not present in the `log4j2.xml` configuration, Sentry will attempt
# Add data like request headers and IP for users,
# see https://docs.sentry.io/platforms/java/guides/log4j2/data-management/data-collected/ for more info
send-default-pii=true
// ___PRODUCT_OPTION_START___ logs
logs.enabled=true
// ___PRODUCT_OPTION_END___ logs
```
</OnboardingOption>

Expand All @@ -80,6 +83,9 @@ Two log levels are used to configure this integration, as illustrated below in t

1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry.
2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`)
<OnboardingOption optionId="logs">
3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`).
</OnboardingOption>

<Alert>

Expand All @@ -96,7 +102,11 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi
<Sentry name="SENTRY"
dsn="___PUBLIC_DSN___"
minimumBreadcrumbLevel="DEBUG"
minimumEventLevel="WARN"/>
minimumEventLevel="WARN"
<!-- ___PRODUCT_OPTION_START___ logs -->
minimumLevel="DEBUG"
<!-- ___PRODUCT_OPTION_END___ logs -->
/>
```
</OnboardingOption>
<OnboardingOption optionId="opentelemetry">
Expand All @@ -105,6 +115,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi
<!-- Setting minimumEventLevel the default minimum level to capture an event from ERROR to WARN -->
<Sentry name="SENTRY"
minimumBreadcrumbLevel="DEBUG"
minimumEventLevel="WARN"/>
minimumEventLevel="WARN"
<!-- ___PRODUCT_OPTION_START___ logs -->
minimumLevel="DEBUG"
<!-- ___PRODUCT_OPTION_END___ logs -->
/>
```
</OnboardingOption>
16 changes: 16 additions & 0 deletions platform-includes/getting-started-config/java.logback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The `ConsoleAppender` is provided only as an example of a non-Sentry appender se
<dsn>___PUBLIC_DSN___</dsn>
<!-- Add data like request headers and IP for users, see https://docs.sentry.io/platforms/java/guides/logback/data-management/data-collected/ for more info -->
<sendDefaultPii>true</sendDefaultPii>
// ___PRODUCT_OPTION_START___ logs
<logs>
<enabled>true</enabled>
</logs>
// ___PRODUCT_OPTION_END___ logs
</options>
</appender>

Expand Down Expand Up @@ -87,6 +92,9 @@ Two log levels are used to configure this integration:

1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry.
2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`).
<OnboardingOption optionId="logs">
3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`).
</OnboardingOption>

<Alert>

Expand All @@ -110,6 +118,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi
<minimumEventLevel>WARN</minimumEventLevel>
<!-- Optionally change minimum Breadcrumbs level. Default for Breadcrumbs is INFO -->
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
// ___PRODUCT_OPTION_START___ logs
<!-- Optionally change minimum Log level. Default for Logs is INFO -->
<minimumLevel>DEBUG</minimumLevel>
// ___PRODUCT_OPTION_END___ logs
</appender>
```
</OnboardingOption>
Expand All @@ -121,6 +133,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi
<minimumEventLevel>WARN</minimumEventLevel>
<!-- Optionally change minimum Breadcrumbs level. Default for Breadcrumbs is INFO -->
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
// ___PRODUCT_OPTION_START___ logs
<!-- Optionally change minimum Log level. Default for Logs is INFO -->
<minimumLevel>DEBUG</minimumLevel>
// ___PRODUCT_OPTION_END___ logs
</appender>
```
</OnboardingOption>
7 changes: 7 additions & 0 deletions platform-includes/getting-started-config/java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ Sentry.init { options ->
// ___PRODUCT_OPTION_END___ logs
}
```
<OnboardingOption optionId="logs">
<Alert>

Learn more about setting up logging in our <PlatformLink to="/logs/">Logs documentation</PlatformLink>.

</Alert>
</OnboardingOption>
</OnboardingOption>
Loading
Loading