Skip to content

Commit 19059bd

Browse files
Add docs for loguru integration (#6617)
* Add docs for `loguru` integration --------- Co-authored-by: Anton Pirker <[email protected]>
1 parent 7e12d0c commit 19059bd

File tree

11 files changed

+132
-10
lines changed

11 files changed

+132
-10
lines changed

src/platforms/python/common/configuration/integrations/asyncio.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: asyncio
33
description: "Learn about the asyncio integration and how it adds support for applications the asyncio module."
4-
sidebar_order: 11
4+
sidebar_order: 20
55
---
66

77
The `AsyncioIntegration` integrates with applications doing concurrent code execution using Pythons [asyncio](https://docs.python.org/3/library/asyncio.html) module.

src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: GNU Backtrace
33
description: "Learn about the GNU backtrace integration and how to add it to your integrations list."
4-
sidebar_order: 70
4+
sidebar_order: 50
55
---
66

77
<!-- NOTE: Due to being in common, redirects are in vercel.json -->

src/platforms/python/common/configuration/integrations/grpc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: GRPC
33
description: "Learn about the gRPC integration and how it adds support for the grpcio grpc client and server."
4-
sidebar_order: 80
4+
sidebar_order: 60
55
---
66

77
The [gRPC](https://grpc.io/) integration instruments all incoming requests and outgoing unary-unary, unary-stream grpc

src/platforms/python/common/configuration/integrations/httpx.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: HTTPX
33
description: "Learn about the HTTPX integration and how it adds support for the HTTPX HTTP client."
4-
sidebar_order: 80
4+
sidebar_order: 70
55
---
66

77
The [HTTPX](https://www.python-httpx.org/) integration instruments outgoing HTTP requests using either the sync or the async HTTPX clients.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: Loguru
3+
description: Learn about using Sentry with Loguru.
4+
sidebar_order: 80
5+
---
6+
7+
The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry.
8+
9+
The [`logging`](/platforms/python/guides/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru.
10+
11+
## Install
12+
13+
Install `sentry-sdk` from PyPI with the Loguru extra.
14+
15+
```bash
16+
pip install --upgrade 'sentry-sdk[loguru]'
17+
```
18+
19+
## Configure
20+
21+
Add `LoguruIntegration()` to your integrations list:
22+
23+
```python
24+
import sentry_sdk
25+
from sentry_sdk.integrations.loguru import LoguruIntegration
26+
27+
sentry_sdk.init(
28+
dsn="___PUBLIC_DSN___",
29+
integrations=[
30+
LoguruIntegration(),
31+
],
32+
)
33+
```
34+
35+
## Behavior
36+
37+
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:
38+
39+
```python
40+
from loguru import logger
41+
42+
logger.debug("I am ignored")
43+
logger.info("I am a breadcrumb")
44+
logger.error("I am an event", extra=dict(bar=43))
45+
logger.exception("An exception happened")
46+
```
47+
48+
- An error event with the message `"I am an event"` will be created.
49+
- `"I am a breadcrumb"` will be attached as a breadcrumb to that event.
50+
- `bar` will end up in the `extra` attributes of that event.
51+
- `"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.
52+
- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`.
53+
54+
### Ignoring a logger
55+
56+
Loggers can be noisy. You can ignore a logger by calling `ignore_logger`.
57+
58+
Since most of the logic is proxied to `logging` integration, we use it instead of the Loguru integration:
59+
60+
```python
61+
# Import form `logging` integration
62+
from sentry_sdk.integrations.logging import ignore_logger
63+
64+
ignore_logger("a.spammy.logger")
65+
```
66+
67+
In `a.spammy.logger` module:
68+
69+
```python
70+
from loguru import logger
71+
logger.error("hi") # No error is sent to Sentry
72+
```
73+
74+
This will work with `logging`'s logger too
75+
76+
```python
77+
logger = logging.getLogger("a.spammy.logger")
78+
logger.error("hi") # Again, no error sent to Sentry
79+
```
80+
81+
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.
82+
83+
## Options
84+
85+
You can pass the following keyword arguments to `LoguruIntegration()`:
86+
87+
```python
88+
import sentry_sdk
89+
from loguru import logger
90+
91+
from sentry_sdk.integrations.loguru import LoguruIntegration
92+
from sentry_sdk.integrations.loguru import LoggingLevels
93+
94+
sentry_loguru = LoguruIntegration(
95+
level=LoggingLevels.INFO.value, # Capture info and above as breadcrumbs
96+
event_level=LoggingLevels.ERROR.value # Send errors as events
97+
)
98+
99+
sentry_sdk.init(
100+
dsn="___PUBLIC_DSN___",
101+
integrations=[
102+
sentry_loguru,
103+
],
104+
)
105+
```
106+
107+
- `level`
108+
109+
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.
110+
111+
Default: `INFO`
112+
113+
- `event_level`
114+
115+
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.
116+
117+
Default: `ERROR`
118+
119+
## Supported Versions
120+
121+
- Loguru: 0.5+
122+
- Python: 3.5+

src/platforms/python/common/configuration/integrations/pure_eval.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Enhanced Locals
33
description: "Learn about `pure_eval` and how to add it to your integrations list."
4-
sidebar_order: 50
4+
sidebar_order: 40
55
---
66

77
<!-- NOTE: Due to being in common, redirects are in vercel.json -->

src/platforms/python/common/configuration/integrations/pymongo.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: PyMongo
33
description: "Learn about the PyMongo integration and how it adds support for connections to MongoDB databases."
4-
sidebar_order: 160
4+
sidebar_order: 100
55
redirect_from:
66
- /platforms/python/guides/pymongo/
77
---

src/platforms/python/common/configuration/integrations/redis.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Redis
33
description: "Learn about importing the Redis integration."
4-
sidebar_order: 180
4+
sidebar_order: 110
55
---
66

77
<!-- NOTE: Due to being in common, redirects are in vercel.json -->

src/platforms/python/common/configuration/integrations/socket.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: SOCKET
33
description: "Learn about the Socket integration and how it adds support network actions."
4-
sidebar_order: 80
4+
sidebar_order: 90
55
---
66

77
Use this integration to create spans for dns resolves and connection creations.

src/platforms/python/common/configuration/integrations/sqlalchemy.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: SQLAlchemy
33
description: "Learn about importing the SQLAlchemy integration and how it captures queries from SQLAlchemy as breadcrumbs."
4-
sidebar_order: 190
4+
sidebar_order: 120
55
redirect_from:
66
- /platforms/python/guides/aws-lambda/integrations/sqlalchemy/
77
- /platforms/python/guides/logging/integrations/sqlalchemy/

src/platforms/python/common/configuration/integrations/wsgi.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: WSGI
33
description: "Learn about the WSGI integration and how it adds support for WSGI applications."
4-
sidebar_order: 220
4+
sidebar_order: 130
55
redirect_from:
66
- /platforms/python/guides/wsgi/
77
---

0 commit comments

Comments
 (0)