---
title: "Logs"
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
url: https://docs.sentry.io/platforms/java/guides/jul/logs/
---

# Set Up Logs | Sentry for java.util.logging

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.

## [Requirements](https://docs.sentry.io/platforms/java/guides/jul/logs.md#requirements)

Logs for JUL are supported in Sentry Java SDK version `8.16.0` and above.

## [Setup](https://docs.sentry.io/platforms/java/guides/jul/logs.md#setup)

To enable logging, you need to configure the option in `sentry.properties` or when calling `Sentry.init`.

```properties
logs.enabled=true
```

You may also configure the Sentry handler and set `minimumLevel` in `logging.properties`:

```properties
# Configure the Sentry handler
handlers=io.sentry.jul.SentryHandler

# Set the minimum level for Sentry handler

io.sentry.jul.SentryHandler.minimumLevel=CONFIG
```

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

Once the handler is configured with logging enabled, any logs at or above the `minimumLevel` will be sent to Sentry.

## [Options](https://docs.sentry.io/platforms/java/guides/jul/logs.md#options)

#### [beforeSendLog](https://docs.sentry.io/platforms/java/guides/jul/logs.md#beforesendlog)

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

```java
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setDsn("___PUBLIC_DSN___");

  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.

#### [contextTags](https://docs.sentry.io/platforms/java/guides/jul/logs.md#contexttags)

You can use the [`contextTags`](https://docs.sentry.io/platforms/java/guides/jul/configuration/options.md#contextTags) option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry.

For detailed configuration examples, see the Advanced Usage documentation for your logging framework.

## [Best Practices](https://docs.sentry.io/platforms/java/guides/jul/logs.md#best-practices)

### [Wide Events Over Scattered Logs](https://docs.sentry.io/platforms/java/guides/jul/logs.md#wide-events-over-scattered-logs)

Instead of many thin logs that are hard to correlate, emit one comprehensive log per operation with all relevant context.

This makes debugging dramatically faster — one query returns everything about a specific order, user, or request.

```java
// ❌ Scattered thin logs
Sentry.logger().info("Starting checkout");
Sentry.logger().info("Validating cart");
Sentry.logger().info("Processing payment");
Sentry.logger().info("Checkout complete");

// ✅ One wide event with full context
Sentry.logger().log(
    SentryLogLevel.INFO,
    SentryLogParameters.create(
        SentryAttributes.of(
            SentryAttribute.stringAttribute("order_id", order.getId()),
            SentryAttribute.stringAttribute("user_id", user.getId()),
            SentryAttribute.stringAttribute("user_tier", user.getSubscription()),
            SentryAttribute.doubleAttribute("cart_value", cart.getTotal()),
            SentryAttribute.integerAttribute("item_count", cart.getItems().size()),
            SentryAttribute.stringAttribute("payment_method", "stripe")
        )
    ),
    "Checkout completed"
);
```

### [Include Business Context](https://docs.sentry.io/platforms/java/guides/jul/logs.md#include-business-context)

Add attributes that help you prioritize and debug:

* **User context** — tier, account age, lifetime value
* **Transaction data** — order value, item count
* **Feature state** — active feature flags
* **Request metadata** — endpoint, method, duration

This lets you filter logs by high-value customers or specific features.

```java
Sentry.logger().log(
    SentryLogLevel.INFO,
    SentryLogParameters.create(
        SentryAttributes.of(
            // User context
            SentryAttribute.stringAttribute("user_id", user.getId()),
            SentryAttribute.stringAttribute("user_tier", user.getPlan()),
            SentryAttribute.integerAttribute("account_age_days", user.getAgeDays()),

            // Request data
            SentryAttribute.stringAttribute("endpoint", "/api/orders"),
            SentryAttribute.stringAttribute("method", "POST"),
            SentryAttribute.integerAttribute("duration_ms", 234),

            // Business context
            SentryAttribute.doubleAttribute("order_value", 149.99)
        )
    ),
    "API request completed"
);
```

### [Consistent Attribute Naming](https://docs.sentry.io/platforms/java/guides/jul/logs.md#consistent-attribute-naming)

Pick a naming convention and stick with it across your codebase. Inconsistent names make queries impossible.

**Recommended:** Use `snake_case` for custom attributes to match common conventions.

```java
// ❌ Inconsistent naming
SentryAttribute.stringAttribute("user", "123")
SentryAttribute.stringAttribute("userId", "123")
SentryAttribute.stringAttribute("user_id", "123")
SentryAttribute.stringAttribute("UserID", "123")

// ✅ Consistent snake_case
SentryAttributes.of(
    SentryAttribute.stringAttribute("user_id", "123"),
    SentryAttribute.stringAttribute("order_id", "456"),
    SentryAttribute.doubleAttribute("cart_value", 99.99),
    SentryAttribute.integerAttribute("item_count", 3)
)
```

## [Default Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#default-attributes)

The Java SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

### [Core Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#core-attributes)

* `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
* `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
* `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`.
* `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`.

### [Message Template Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#message-template-attributes)

If the log was parameterized, Sentry adds the message template and parameters as log attributes.

* `message.template`: The parameterized template string. This is sent from the SDK as `sentry.message.template`.
* `message.parameter.X`: The parameters to fill the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc). This is sent from the SDK as `sentry.message.parameter.X`.

For example, with the following log:

```java
Sentry.logger().error("A %s log message", "formatted");
```

Sentry will add the following attributes:

* `message.template`: "A %s log message"
* `message.parameter.0`: "formatted"

### [Server Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#server-attributes)

* `server.address`: The address of the server that sent the log. Equivalent to `server_name` that gets attached to Sentry errors.

### [User Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#user-attributes)

If user information is available in the current scope, the following attributes are added to the log:

* `user.id`: The user ID.
* `user.name`: The username.
* `user.email`: The email address.

### [Integration Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#integration-attributes)

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

* `origin`: The origin of the log. This is sent from the SDK as `sentry.origin`.

### [Scope Attributes](https://docs.sentry.io/platforms/java/guides/jul/logs.md#scope-attributes)

Any attributes set on the current scope via `Sentry.setAttribute()` or `Sentry.setAttributes()` are automatically included on all log entries. See [Usage](https://docs.sentry.io/platforms/java/guides/jul/logs.md#usage) above for details.

## [Other Logging Integrations](https://docs.sentry.io/platforms/java/guides/jul/logs.md#other-logging-integrations)

Available integrations:

* [Spring Boot using Logback](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/logback.md)
* [Spring Boot using Log4j2](https://docs.sentry.io/platforms/java/guides/spring-boot/logging-frameworks/log4j2.md)
* [Logback](https://docs.sentry.io/platforms/java/guides/logback/logs.md)
* [Log4j2](https://docs.sentry.io/platforms/java/guides/log4j2/logs.md)

If there's an integration you would like to see, open a [new issue on GitHub](https://github.com/getsentry/sentry-java/issues/new/choose).
