# Set Up Logs

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

##### Now in Beta

Sentry Logs is currently in Beta. Features are still in-progress and may have bugs. We recognize the irony. For any questions or feedback, you can reach us on [Discord](https://discord.gg/sentry) or [GitHub](https://github.com/getsentry/sentry/discussions/86804).

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](#requirements)

Logs for Android are supported in Sentry Java SDK version `8.12.0` and above.

## [Setup](#setup)

To enable logging, you need to initialize the SDK with the `logs.enabled` option set to `true`.

```java
import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroid;
import android.app.Application;

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    SentryAndroid.init(this, options -> {
      options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");

      options.getLogs().setEnabled(true);

    });
  }
}
```

## [Usage](#usage)

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `Sentry.logger()` APIs.

The `Sentry.logger()` namespace exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.

For more advanced use cases, use the `Sentry.logger().log()` methods.

These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

```java
import io.sentry.Sentry;

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

## [Integrations](#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](https://github.com/getsentry/sentry-java/issues/new/choose) for any integration you would like to see.

* [Timber](https://github.com/getsentry/sentry-java/issues/4407)
* [Logcat](https://github.com/getsentry/sentry-java/issues/4408)

## [Options](#options)

#### [beforeSendLog](#beforesendlog)

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

```java
import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroid;
import android.app.Application;

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    SentryAndroid.init(this, 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.
