java.util.logging
The sentry-jul
library provides a java.util.logging Handler that sends logged exceptions to Sentry.
Once this integration is configured you can also use Sentry’s static API, as shown on the usage page, in order to do things like record breadcrumbs, set the current user, or manually send events. The source can be found on GitHub.
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.
Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.
Install
Sentry captures data by using an SDK within your application’s runtime.
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-jul</artifactId>
<version>7.13.0</version>
</dependency>
For other dependency managers, see the central Maven repository.
Sentry's Java SDK depends on Gson as a transitive dependency; the minimum required version is 2.7.
If you are using multiple Sentry dependencies, you can add a bill of materials to avoid specifying the version of each dependency.
Configure
Configuration should happen as early as possible in your application's lifecycle.
The following example configures a ConsoleHandler
that logs to standard out at the INFO
level and a SentryHandler
that logs to the Sentry server at the WARN
level. The ConsoleHandler
is only provided as an example of a non-Sentry appender that is set to a different logging threshold, like one you may already have in your project.
The ConsoleHandler
is provided only as an example of a non-Sentry appender set to a different logging threshold, similar to what you may already have in your project.
Example configuration using the logging.properties
format:
# Enable the Console and Sentry handlers
handlers=java.util.logging.ConsoleHandler,io.sentry.jul.SentryHandler
# Set the default log level to INFO
.level=INFO
# Override the Sentry handler log level to WARNING
io.sentry.jul.SentryHandler.level=WARNING
When starting your application, add the java.util.logging.config.file
to the system properties, with the full path to the logging.properties
as its value:
java -Djava.util.logging.config.file=/path/to/app.properties MyClass
DSN Configuration
Sentry reads the DSN from the system property sentry.dsn
, environment variable SENTRY_DSN
or the dsn
property in sentry.properties
file. See the configuration page for more details on external configuration.
dsn=https://examplePublicKey@o0.ingest.sentry.io/0
Minimum Log Level
Two log levels are used to configure this integration:
- Configure the lowest level required for a log message to become an event (
minimumEventLevel
) sent to Sentry. - Configure the lowest level a message has to be to become a breadcrumb (
minimumBreadcrumbLevel
).
Breadcrumbs are kept in memory (by default the last 100 records) and are sent with events. For example, by default, if you log 100 entries with logger.config
or logger.warn
, no event is sent to Sentry. If you then log with logger.error
, an event is sent to Sentry which includes those 100 config
or warning
messages. For this to work, SentryHandler
needs to receive all log entries to decide what to keep as breadcrumb or send as event. Set the SentryHandler
log level configuration to a value lower than what is set for the minimumBreadcrumbLevel
and minimumEventLevel
so that SentryHandler
receives these log messages.
io.sentry.jul.SentryHandler.minimumEventLevel=INFO
io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG
io.sentry.jul.SentryHandler.level=CONFIG
...
String Formatting Style
By default, MessageFormat#format method is used to render parameterized log messages. It can be changed to use String#format by setting printfStyle
property to true
:
io.sentry.jul.SentryHandler.printfStyle=true
Verify
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
import io.sentry.Sentry;
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
Learn more about manually capturing an error or message in our Usage documentation.
To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
- Package:
- maven:io.sentry:sentry-jul
- Version:
- 7.13.0
- Repository:
- https://github.com/getsentry/sentry-java