Skip to content

Commit f866253

Browse files
committed
ref(loguru): Update Loguru docs to mention Logs more prominently
1 parent 66c133c commit f866253

File tree

1 file changed

+41
-37
lines changed
  • docs/platforms/python/integrations/loguru

1 file changed

+41
-37
lines changed

docs/platforms/python/integrations/loguru/index.mdx

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Loguru
33
description: Learn about using Sentry with Loguru.
44
---
55

6-
The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry.
6+
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.
77

88
The [`logging`](/platforms/python/integrations/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru.
99

@@ -21,7 +21,7 @@ uv add "sentry-sdk[loguru]"
2121

2222
## Configure
2323

24-
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`.
24+
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.
2525

2626
```python
2727
import sentry_sdk
@@ -42,47 +42,50 @@ from loguru import logger
4242

4343
def main():
4444
sentry_sdk.init(...) # same as above
45-
logger.debug("I am ignored")
46-
logger.error("There was an error!")
45+
logger.info("Logging some info")
4746

4847
main()
4948
```
5049

51-
This will capture the `error` level log entry and send it as an error to Sentry.
50+
This will capture the `INFO` level log and send it to Sentry logs.
51+
5252

5353
## Behavior
5454

55-
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:
55+
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.
5656

57-
```python
58-
from loguru import logger
57+
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).
5958

60-
logger.debug("I am ignored")
61-
logger.info("I am a breadcrumb")
62-
logger.error("I am an event", extra=dict(bar=43))
63-
logger.exception("An exception happened")
64-
```
59+
`INFO` and above logs will also be captured as breadcrumbs. Use the [`level` integration option](#options) to adjust the threshold.
6560

66-
- An error event with the message `"I am an event"` will be created.
67-
- `"I am a breadcrumb"` will be attached as a breadcrumb to that event.
68-
- `bar` will end up in the `extra` attributes of that event.
69-
- `"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.
70-
- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`.
71-
72-
Loguru log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` option is `True`.
61+
The following snippet demonstrates the default behavior:
7362

7463
```python
7564
import sentry_sdk
7665
from loguru import logger
7766

7867
sentry_sdk.init(
79-
# ...
68+
...,
8069
enable_logs=True,
8170
)
8271

83-
logger.info("I will be sent to Sentry logs")
72+
# The following will be captured as Sentry logs:
73+
logger.info("I'm an INFO log")
74+
logger.error("I'm an ERROR log", extra={"bar": 43})
75+
logger.exception("I'm an exception log")
76+
77+
# DEBUG-level logs won't be captured by default
78+
logger.debug("I'm a DEBUG log")
8479
```
8580

81+
- All of the above logs except for the `DEBUG` level message will be sent to Sentry as logs.
82+
- An error event with the message `"I'm an exception log"` will be created..
83+
- `"I'm an INFO log"` will be attached as a breadcrumb to that event.
84+
- `bar` will end up in the `extra` attributes of that event.
85+
- `"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.
86+
- 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.
87+
88+
8689
### Ignoring a logger
8790

8891
Loggers can be noisy. You can ignore a logger by calling `ignore_logger`.
@@ -100,17 +103,17 @@ In `a.spammy.logger` module:
100103

101104
```python
102105
from loguru import logger
103-
logger.error("hi") # No error is sent to Sentry
106+
logger.error("hi") # Nothing is sent to Sentry
104107
```
105108

106109
This will work with `logging`'s logger too
107110

108111
```python
109112
logger = logging.getLogger("a.spammy.logger")
110-
logger.error("hi") # Again, no error sent to Sentry
113+
logger.error("hi") # Again, nothing is sent to Sentry
111114
```
112115

113-
You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See <PlatformLink to="/configuration/filtering/">Filtering Events</PlatformLink> for more information.
116+
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 <PlatformLink to="/configuration/filtering/">Filtering Events</PlatformLink> for more information.
114117

115118
## Options
116119

@@ -127,25 +130,14 @@ sentry_sdk.init(
127130
# ...
128131
integrations=[
129132
LoguruIntegration(
133+
sentry_logs_level=LoggingLevels.INFO.value, # Capture INFO and above as logs
130134
level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs
131135
event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events
132-
sentry_logs_level=LoggingLevels.INFO.value, # Capture INFO and above as logs
133136
)
134137
],
135138
)
136139
```
137140

138-
- `level`
139-
140-
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.
141-
142-
Default: `INFO`
143-
144-
- `event_level`
145-
146-
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.
147-
148-
Default: `ERROR`
149141

150142
- `sentry_logs_level`
151143

@@ -162,6 +154,18 @@ sentry_sdk.init(
162154

163155
Default: `INFO`
164156

157+
- `level`
158+
159+
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.
160+
161+
Default: `INFO`
162+
163+
- `event_level`
164+
165+
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.
166+
167+
Default: `ERROR`
168+
165169
## Supported Versions
166170

167171
- Loguru: 0.5+

0 commit comments

Comments
 (0)