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 Log4j2 are supported in Sentry Java SDK version 8.16.0
and above.
To enable logging, you need to configure the option in sentry.properties
or when calling Sentry.init
.
logs.enabled=true
You may also set minimumLevel
in log4j2.xml
to configure which log messages are sent to Sentry.
<Sentry
name="Sentry"
dsn="your DSN"
minimumBreadcrumbLevel="DEBUG"
minimumEventLevel="WARN"
minimumLevel="DEBUG"
/>
Once the handler is configured with logging enabled, any logs at or above the minimumLevel
will be sent to Sentry.
Available integrations:
If there's an integration you would like to see, open a new issue on GitHub.
To filter logs, or update them before they are sent to Sentry, you can use the getLogs().beforeSend
option.
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.
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").