---
title: "Loguru"
description: "Learn about using Sentry with Loguru."
url: https://docs.sentry.io/platforms/python/integrations/loguru/
---

# Loguru | Sentry for Python

The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry.

The [`logging`](https://docs.sentry.io/platforms/python/integrations/logging.md) integration provides most of the Loguru functionality and most examples on that page work with Loguru.

##### Sentry Logs for Loguru

Enable the Sentry Logs feature with `sentry_sdk.init(enable_logs=True)` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.

## [Install](https://docs.sentry.io/platforms/python/integrations/loguru.md#install)

Install `sentry-sdk` from PyPI:

```bash
pip install sentry-sdk
```

## [Configure](https://docs.sentry.io/platforms/python/integrations/loguru.md#configure)

To capture Loguru log records as [Sentry logs](https://docs.sentry.io/platforms/python/logs.md), set `enable_logs` to `True`. The integration itself doesn't need to be added manually. If you have the `loguru` package in your dependencies, the Loguru integration will be enabled automatically when you initialize the Sentry SDK.

```python
import sentry_sdk

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    enable_logs=True,
)
```

## [Verify](https://docs.sentry.io/platforms/python/integrations/loguru.md#verify)

```python
from loguru import logger

def main():
    sentry_sdk.init(...)  # same as above
    logger.info("Logging some info")
    logger.error("Logging an error")

main()
```

This will capture both logs and send them to Sentry Logs. Additionally, an error event will be created from the `ERROR`-level log. In addition to that, a breadcrumb will be created from the `INFO`-level log.

## [Behavior](https://docs.sentry.io/platforms/python/integrations/loguru.md#behavior)

Logs with a level of `INFO` and higher will be captured as Sentry logs as long as `enable_logs` is `True` and the log level set in the `logging` module is `INFO` or below. The threshold can be configured via the [`sentry_logs_level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options).

Additionally, the Loguru integration will create an error event from all `ERROR`-level logs. This feature is configurable via the [`event_level` integration option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options).

`INFO` and above logs will also be captured as breadcrumbs. Use the [`level` integration option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options) to adjust the threshold.

The following snippet demonstrates the default behavior:

```python
import sentry_sdk
from loguru import logger

sentry_sdk.init(
    ...,
    enable_logs=True,
)

# The following will be captured as Sentry logs:
logger.info("I'm an INFO log")
logger.error("I'm an ERROR log", extra={"bar": 43})
logger.exception("I'm an exception log")

# DEBUG-level logs won't be captured by default
logger.debug("I'm a DEBUG log")
```

* All of the above logs except for the `DEBUG`-level message will be sent to Sentry as logs.
* An error event with the message `"I'm an ERROR log"` will be created.
* `"I'm an INFO log"` will be attached as a breadcrumb to that event.
* `bar` will end up in the `extra` attributes of that event.
* `"I'm an exception log"` will send the current exception from `sys.exc_info()` with the stack trace to Sentry. If there's no exception, the current stack will be attached.
* The debug message `"I'm a DEBUG log"` will not be captured by Sentry. See the [`sentry_logs_level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#option) to adjust which log levels should be sent to Sentry as logs, and the [`level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#option) to adjust the level for capturing breadcrumbs.

### [Ignoring a logger](https://docs.sentry.io/platforms/python/integrations/loguru.md#ignoring-a-logger)

Loggers can be noisy. You can ignore a logger by calling `ignore_logger`.

Since most of the logic is proxied to `logging` integration, we use it instead of the Loguru integration:

```python
# Import form `logging` integration
from sentry_sdk.integrations.logging import ignore_logger

ignore_logger("a.spammy.logger")
```

In `a.spammy.logger` module:

```python
from loguru import logger
logger.error("hi")  # Nothing is sent to Sentry
```

This will work with `logging`'s logger too

```python
logger = logging.getLogger("a.spammy.logger")
logger.error("hi") # Again, nothing is sent to Sentry
```

You can also use `before_send_log` (for Sentry logs), `before_send` (for Sentry errors) and `before_breadcrumb` (for breadcrumbs) to ignore only certain messages. See [Filtering Events](https://docs.sentry.io/platforms/python/configuration/filtering.md) for more information.

## [Options](https://docs.sentry.io/platforms/python/integrations/loguru.md#options)

You can pass the following keyword arguments to `LoguruIntegration()`:

```python
import sentry_sdk
from loguru import logger

from sentry_sdk.integrations.loguru import LoguruIntegration
from sentry_sdk.integrations.loguru import LoggingLevels

sentry_sdk.init(
    # ...
    integrations=[
        LoguruIntegration(
            sentry_logs_level=LoggingLevels.INFO.value,  # Capture INFO and above as logs
            level=LoggingLevels.INFO.value,              # Capture INFO and above as breadcrumbs
            event_level=LoggingLevels.ERROR.value,       # Send ERROR logs as events
        )
    ],
)
```

* `sentry_logs_level`

  The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](https://docs.sentry.io/platforms/python/logs.md). If set to `None`, the SDK won't send records as logs.

  To capture Loguru log records as Sentry logs, you must enable the `enable_logs` option when initializing the SDK (regardless of the `sentry_logs_level` setting).

  ```python
  sentry_sdk.init(
      # ...
      enable_logs=True,
  )
  ```

  Default: `INFO`

* `level`

  The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK will not capture breadcrumbs for logs with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs.

  Default: `INFO`

* `event_level`

  The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If set to `None`, the SDK won't send log records as events.

  Default: `ERROR`

## [Troubleshooting](https://docs.sentry.io/platforms/python/integrations/loguru.md#troubleshooting)

Logs not appearing in Sentry

First, make sure you have the `enable_logs=True` option in your `sentry_sdk.init()` and you're on the latest version of the SDK.

Your logs could be missing because of the logging level of the logger. The SDK will honor the configured level of each logger. That means that you won't see any `INFO` or `DEBUG` data in Sentry from a logger with the level set to `WARNING`, regardless of how you configure the integration.

It might also be the case that the SDK's Loguru setup is being overwritten in your app. Sentry plugs into Loguru by adding its own handlers when you call `sentry_sdk.init()`. If those handlers are later overridden, for example by calling `logger.configure(handlers=...)`, the integration won't work.

Another reason why you might not be seeing your logs in Sentry is because they were rejected client- or server-side. This could be due to them being too large, or because of reasons like rate limits or backpressure management. In Sentry, you can go to `Settings > Stats & Usage` and select `Logs` from the `Category` dropdown to see what logs were dropped.

## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/loguru.md#supported-versions)

* Loguru: 0.5+
* Python: 3.6+

The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.
