From f866253d395005e2d71f29a3a8e1e5bbf80139ee Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Mon, 17 Nov 2025 16:35:23 +0100 Subject: [PATCH 1/7] ref(loguru): Update Loguru docs to mention Logs more prominently --- .../python/integrations/loguru/index.mdx | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 441edcd976e15..e453379bfe663 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -3,7 +3,7 @@ title: Loguru description: Learn about using Sentry with Loguru. --- -The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. +The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. Depending on your settings, Loguru logs can be captured as Sentry logs, as error events, or as breadcrumbs, or a combination of those. The [`logging`](/platforms/python/integrations/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru. @@ -21,7 +21,7 @@ uv add "sentry-sdk[loguru]" ## Configure -If you have the `loguru` package in your dependencies, the Loguru integration will be enabled automatically when you initialize the Sentry SDK. To capture Loguru log records as [Sentry logs](/platforms/python/logs/), set `enable_logs` to `True`. +To capture Loguru log records as [Sentry logs](/platforms/python/logs/), 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 @@ -42,47 +42,50 @@ from loguru import logger def main(): sentry_sdk.init(...) # same as above - logger.debug("I am ignored") - logger.error("There was an error!") + logger.info("Logging some info") main() ``` -This will capture the `error` level log entry and send it as an error to Sentry. +This will capture the `INFO` level log and send it to Sentry logs. + ## Behavior -By default, logs with a level of `INFO` or higher will be added as breadcrumbs to Sentry events. Sentry issue will be created for logs with a level of `ERROR` or higher: +As long as `enable_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs. The threshold can be configured via the [`sentry_logs_level` option](#options) TODO LINK. -```python -from loguru import logger +Additionally, the Loguru integration will create an error event from all `ERROR`-level logs. This feature is configurable via the [`event_level` integration option](#options). -logger.debug("I am ignored") -logger.info("I am a breadcrumb") -logger.error("I am an event", extra=dict(bar=43)) -logger.exception("An exception happened") -``` +`INFO` and above logs will also be captured as breadcrumbs. Use the [`level` integration option](#options) to adjust the threshold. -- An error event with the message `"I am an event"` will be created. -- `"I am a breadcrumb"` will be attached as a breadcrumb to that event. -- `bar` will end up in the `extra` attributes of that event. -- `"An exception happened"` 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 am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`. - -Loguru log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` option is `True`. +The following snippet demonstrates the default behavior: ```python import sentry_sdk from loguru import logger sentry_sdk.init( - # ... + ..., enable_logs=True, ) -logger.info("I will be sent to Sentry logs") +# 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 exception 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](#option) to adjust which levels should be sent to Sentry as logs, and the [`level` option](#option) to do adjust the level for capturing breadcrumbs. + + ### Ignoring a logger Loggers can be noisy. You can ignore a logger by calling `ignore_logger`. @@ -100,17 +103,17 @@ In `a.spammy.logger` module: ```python from loguru import logger -logger.error("hi") # No error is sent to Sentry +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, no error sent to Sentry +logger.error("hi") # Again, nothing is sent to Sentry ``` -You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See Filtering Events for more information. +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 for more information. ## Options @@ -127,25 +130,14 @@ 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=LoggingLevels.INFO.value, # Capture INFO and above as logs ) ], ) ``` -- `level` - - The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK ignores any log record 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` - `sentry_logs_level` @@ -162,6 +154,18 @@ sentry_sdk.init( 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` + ## Supported Versions - Loguru: 0.5+ From 7c5c7064a585f3db0bb66c8ee3b2a527539c97c0 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Mon, 17 Nov 2025 17:04:27 +0100 Subject: [PATCH 2/7] better example, fix link --- docs/platforms/python/integrations/loguru/index.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index e453379bfe663..97ddf1af2164f 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -43,16 +43,17 @@ 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 the `INFO` level log and send it to Sentry logs. +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 -As long as `enable_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs. The threshold can be configured via the [`sentry_logs_level` option](#options) TODO LINK. +As long as `enable_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs. The threshold can be configured via the [`sentry_logs_level` option](#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](#options). From 0799638f497abf4b8d668dea62f21fa4b43dc3ff Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Mon, 17 Nov 2025 17:19:43 +0100 Subject: [PATCH 3/7] tweaks --- docs/platforms/python/integrations/loguru/index.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 97ddf1af2164f..2fe1033afcb5b 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -79,12 +79,12 @@ logger.exception("I'm an exception log") 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 exception log"` will be created.. +- 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 exception 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](#option) to adjust which levels should be sent to Sentry as logs, and the [`level` option](#option) to do adjust the level for capturing breadcrumbs. +- The debug message `"I'm a DEBUG log"` will not be captured by Sentry. See the [`sentry_logs_level` option](#option) to adjust which log levels should be sent to Sentry as logs, and the [`level` option](#option) to adjust the level for capturing breadcrumbs. ### Ignoring a logger From 55c0ac6c3470f9424dbaa32b14aa87b7d390407d Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 18 Nov 2025 07:50:01 +0100 Subject: [PATCH 4/7] fix --- docs/platforms/python/integrations/loguru/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 2fe1033afcb5b..df6f886f44790 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -80,7 +80,7 @@ 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 exception log"` will be created. +- 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. From 36d05ddf218499e9c785190457939b5e76796a9f Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 18 Nov 2025 11:19:25 +0100 Subject: [PATCH 5/7] Update docs/platforms/python/integrations/loguru/index.mdx Co-authored-by: Alex Alderman Webb --- docs/platforms/python/integrations/loguru/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index df6f886f44790..5908f2f6dcfe2 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -53,7 +53,7 @@ This will capture both logs and send them to Sentry Logs. Additionally, an error ## Behavior -As long as `enable_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs. The threshold can be configured via the [`sentry_logs_level` option](#options). +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](#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](#options). From ab71925e930cbbfd840c1b480ab38fbb8c515000 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 18 Nov 2025 11:26:45 +0100 Subject: [PATCH 6/7] alert --- docs/platforms/python/integrations/loguru/index.mdx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 5908f2f6dcfe2..bd775566cd82a 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -3,10 +3,17 @@ title: Loguru description: Learn about using Sentry with Loguru. --- -The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. Depending on your settings, Loguru logs can be captured as Sentry logs, as error events, or as breadcrumbs, or a combination of those. +The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. The [`logging`](/platforms/python/integrations/logging) integration provides most of the Loguru functionality and most examples on that page work with 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 Install `sentry-sdk` from PyPI with the `loguru` extra. From 6db878b6c9e219b2e292f3048eaf01a7b7ccf402 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Tue, 18 Nov 2025 11:53:25 +0100 Subject: [PATCH 7/7] fix header --- docs/platforms/python/integrations/loguru/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index bd775566cd82a..2232cb4b52f6f 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -7,7 +7,7 @@ The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you captu The [`logging`](/platforms/python/integrations/logging) integration provides most of the Loguru functionality and most examples on that page work with 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.