| title | Logging Framework Integrations |
|---|---|
| sidebar_order | 6 |
| description | Learn more about using one of our logging integrations with Sentry 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.
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:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>{{@inject packages.version('sentry.java.logback', '4.2.0') }}</version>
</dependency>implementation 'io.sentry:sentry-logback:{{@inject packages.version('sentry.java.logback', '4.2.0') }}'Minimum logging levels for SentryAppender can be configured in application.properties or application.yml file.
sentry.logging.minimum-event-level=info
sentry.logging.minimum-breadcrumb-level=debug
sentry.logging.minimum-level=debugThe default values are:
infoor higher to include a log message as breadcrumb.infoor higher will send a log message to Sentry and will show up in the Logs section.erroror 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:
sentry.logs.enabled=trueWhen SentryAppender auto-configuration does not suit your needs, it can be turned off by setting:
sentry.logging.enabled=falseIf 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 version="1.0" encoding="UTF-8"?>
<configuration>
<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" />
<root>
<appender-ref ref="CONSOLE" />
<appender-ref ref="SENTRY" />
</root>
</configuration>You do not need to configure your DSN in the Logback 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 Logback and Spring Boot configurations.
Starting with Sentry Java SDK version 8.24.0, you can use the contextTags option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.
To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the sentry-log4j2 module:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}</version>
</dependency>implementation 'io.sentry:sentry-log4j2:{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}'libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}"For other dependency managers see the central Maven repository.
Then follow the guide on configuring Log4j 2 with Spring Boot and configure SentryAppender in the log4j2.xml file:
<?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>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.
Starting with Sentry Java SDK version 8.24.0, you can use the contextTags option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.