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

# Loguru 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.

This page describes the Loguru integration in version `3.x` of the Python SDK. For `2.x`, switch to `2.x` in the version selector.

##### Sentry Logs for Loguru

Add `LoguruIntegration()` to your `integrations` to send Loguru log records as Sentry logs. 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
```

*Other available variations of the above snippet: uv*

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

To use the integration, add `LoguruIntegration()` to your `integrations` list:

```python
import sentry_sdk
from sentry_sdk.integrations.loguru import LoguruIntegration

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    integrations=[
        LoguruIntegration(),
    ],
)
```

## [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 sends both log records to Sentry as [Sentry logs](https://docs.sentry.io/platforms/python/logs.md) and record them as breadcrumbs.

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

By default, logs with a level of `INFO` and higher are captured as Sentry logs. Use the [`level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options) to change the threshold.

`INFO` and above logs are also recorded as breadcrumbs. Use the [`breadcrumb_level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options) to change the threshold.

The integration doesn't create error events from log records by default. To create error events from `ERROR` logs and higher, set the [`event_level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options).

The following snippet demonstrates the behavior with `event_level` set:

```python
import sentry_sdk
from loguru import logger
from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration

sentry_sdk.init(
    ...,
    integrations=[
        LoguruIntegration(event_level=LoggingLevels.ERROR.value),
    ],
)

# 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 are 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"` isn't captured. See the [`level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options) to adjust which log levels should be sent to Sentry as logs, and the [`breadcrumb_level` option](https://docs.sentry.io/platforms/python/integrations/loguru.md#options) to adjust the level for capturing breadcrumbs.

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

To stop a noisy logger from creating events and breadcrumbs, call `ignore_logger_for_events`.

Since most of the logic is proxied to the `logging` integration, import it from there:

```python
# Import from `logging` integration
from sentry_sdk.integrations.logging import ignore_logger_for_events

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

In `a.spammy.logger` module:

```python
from loguru import logger
logger.error("hi")  # No error event or breadcrumb is created
```

This will work with `logging`'s logger too:

```python
logger = logging.getLogger("a.spammy.logger")
logger.error("hi")  # Again, no error event or breadcrumb is created
```

`ignore_logger_for_events` doesn't affect Sentry logs. To filter Loguru records out of Sentry logs, use `before_send_log`.

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(
            level=LoggingLevels.INFO.value,             # Capture INFO and above as logs
            breadcrumb_level=LoggingLevels.INFO.value,  # Capture INFO and above as breadcrumbs
            event_level=LoggingLevels.ERROR.value,      # Send ERROR logs as events
        )
    ],
)
```

Pass these options as keyword arguments. Their position in the `LoguruIntegration()` signature isn't guaranteed to stay the same.

* `level`

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

  Default: `INFO`

* `breadcrumb_level`

  The SDK records log records with a level higher than or equal to `breadcrumb_level` as breadcrumbs. If set to `None`, the SDK won't record log records as breadcrumbs.

  Default: `INFO`

* `event_level`

  The SDK reports 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: `None`

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

Logs not appearing in Sentry

First, make sure you're on the latest version of the SDK. If you're using the `sentry_sdk.logger` API directly (e.g., `sentry_sdk.logger.info(...)`), logs are sent automatically. If you're using Loguru and want those log records captured as Sentry logs, make sure you've added `LoguruIntegration()` to your `integrations` and that its `level` option isn't set to `None`.

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**](https://sentry.io/orgredirect/organizations/:orgslug/settings/stats/) and select `Logs` from the `Category` dropdown to see what logs were dropped.

Error events no longer created from logs

Starting with SDK `3.0`, the Loguru integration doesn't create error events from log records by default. Set `event_level=LoggingLevels.ERROR.value` on `LoguruIntegration()` to create error events from `ERROR` logs and higher.

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

* Loguru: 0.7.0+
* Python: 3.7+

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