Logging Framework Integrations

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:

Copied
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-logback</artifactId>
    <version>8.0.0</version>
</dependency>

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

Copied
sentry.logging.minimum-event-level=info
sentry.logging.minimum-breadcrumb-level=debug

The default values are:

  • info or higher to include a log message as breadcrumb.
  • error or higher will send an event to Sentry.

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

Copied
sentry.logging.enabled=false

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:

Copied
<?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>

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

Copied
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-log4j2</artifactId>
    <version>8.0.0</version>
</dependency>

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:

Copied
<?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>
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").