---
title: "java.util.logging"
url: https://docs.sentry.io/platforms/java/guides/jul/legacy/logging/
---

# java.util.logging | Sentry for java.util.logging

##### Note

An [updated Java SDK](https://docs.sentry.io/platforms/java.md) supersedes this deprecated version. Sentry preserves this documentation for customers using the old client. We recommend using the updated Java SDK for new projects.

The `sentry` library provides a [java.util.logging Handler](http://docs.oracle.com/javase/8/docs/api/java/util/logging/Handler.html) 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](https://docs.sentry.io/platforms/java/legacy/usage.md), in order to do things like record breadcrumbs, set the current user, or manually send events.

The source for `sentry` can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/master/sentry).

### [Installation](https://docs.sentry.io/platforms/java/guides/jul/legacy/logging.md#installation)

```xml
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry</artifactId>
    <version>1.7.30</version>
</dependency>
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry).

### [Usage](https://docs.sentry.io/platforms/java/guides/jul/legacy/logging.md#usage)

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.

Example configuration using the `logging.properties` format:

```ini
# 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:

```bash
java -Djava.util.logging.config.file=/path/to/app.properties MyClass
```

Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](https://docs.sentry.io/platforms/java/legacy/configuration.md#setting-the-dsn) for ways you can do this.

### [In Practice](https://docs.sentry.io/platforms/java/guides/jul/legacy/logging.md#in-practice)

```java
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyClass {
  private static final Logger logger = Logger.getLogger(MyClass.class.getName());

  void logSimpleMessage() {
    // This sends a simple event to Sentry
    logger.error(Level.INFO, "This is a test");
  }

  void logWithBreadcrumbs() {
    // Record a breadcrumb that will be sent with the next event(s),
    // by default the last 100 breadcrumbs are kept.
    Sentry.record(
        new BreadcrumbBuilder().setMessage("User made an action").build()
    );

    // This sends a simple event to Sentry
    logger.error("This is a test");
  }

  void logException() {
    try {
      unsafeMethod();
    } catch (Exception e) {
      // This sends an exception event to Sentry
      logger.error(Level.SEVERE, "Exception caught", e);
    }
  }

  void unsafeMethod() {
    throw new UnsupportedOperationException("You shouldn't call this!");
  }
}
```
