Set Up Logs

Structured logs allow you to send, view and query logs sent from your applications within Sentry.

With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

Logs for Logback are supported in Sentry Java SDK version 8.15.0 and above.

To enable logging, you need to configure the option in the appender configuration. You may also set minimumLevel to configure which log messages are sent to Sentry.

Copied
<appender name="sentry" class="io.sentry.logback.SentryAppender">
  <options>
    <!-- NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard -->
    <dsn>https://examplePublicKey@o0.ingest.sentry.io/0</dsn>
<logs> <enabled>true</enabled> </logs>
</options> <!-- Demonstrates how to modify the minimum values --> <!-- Default for Events is ERROR --> <minimumEventLevel>WARN</minimumEventLevel> <!-- Default for Breadcrumbs is INFO --> <minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel> <!-- Default for Log Events is INFO -->
<minimumLevel>DEBUG</minimumLevel>
</appender>

Once the appender has been configured with logs enabled any logs equal to or higher than minimumLevel will be sent to Sentry as logs.

Available integrations:

We're actively working on adding more integration support for Logs. You can follow progress on the following GitHub issues or open a new one for any integration you would like to see.

To filter logs, or update them before they are sent to Sentry, you can use the getLogs().beforeSend option.

Copied
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");
options.getLogs().setBeforeSend((logEvent) -> { // Modify the event here: logEvent.setBody("new message body"); return logEvent; });
});

The beforeSend function receives a log object, and should return the log object if you want it to be sent to Sentry, or null if you want to discard it.

Was this helpful?
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").