-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add docs for loguru
integration
#6617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22e5c24
Add docs for `loguru` integration
PerchunPak 3857d0b
Small fixes and improvements
PerchunPak 4189fb7
Merge branch 'master' into loguru-integration
PerchunPak ec2ef94
Move loguru docs to configuration directory
PerchunPak c0e507a
Updated docs to be more consistent with other docs pages.
antonpirker a575097
Fixed link
antonpirker 4ed8f73
Fixed markup
antonpirker 63f4e09
Apply suggestions from ~~code~~ grammar review
PerchunPak a7733c0
Resolved one discussion
antonpirker 6fd804f
Resolved some confusion
antonpirker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/asyncio.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/grpc.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/httpx.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/platforms/python/common/configuration/integrations/loguru.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
title: Loguru | ||
description: Learn about using Sentry with Loguru. | ||
sidebar_order: 80 | ||
--- | ||
|
||
The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. | ||
|
||
The [`logging`](/platforms/python/guides/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru. | ||
|
||
## Install | ||
|
||
Install `sentry-sdk` from PyPI with the Loguru extra. | ||
|
||
```bash | ||
pip install --upgrade 'sentry-sdk[loguru]' | ||
``` | ||
|
||
## Configure | ||
|
||
Add `LoguruIntegration()` to your integrations list: | ||
|
||
```python | ||
import sentry_sdk | ||
from sentry_sdk.integrations.loguru import LoguruIntegration | ||
|
||
sentry_sdk.init( | ||
dsn="___PUBLIC_DSN___", | ||
integrations=[ | ||
LoguruIntegration(), | ||
], | ||
) | ||
``` | ||
|
||
## 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: | ||
|
||
```python | ||
from loguru import logger | ||
|
||
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") | ||
``` | ||
|
||
- 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`. | ||
|
||
### 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 | ||
antonpirker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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") # No error 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 | ||
``` | ||
|
||
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. | ||
|
||
## 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_loguru = LoguruIntegration( | ||
level=LoggingLevels.INFO.value, # Capture info and above as breadcrumbs | ||
event_level=LoggingLevels.ERROR.value # Send errors as events | ||
) | ||
|
||
sentry_sdk.init( | ||
dsn="___PUBLIC_DSN___", | ||
integrations=[ | ||
sentry_loguru, | ||
], | ||
) | ||
``` | ||
|
||
- `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` | ||
|
||
## Supported Versions | ||
|
||
- Loguru: 0.5+ | ||
- Python: 3.5+ |
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/pure_eval.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/pymongo.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/redis.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/socket.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/sqlalchemy.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/platforms/python/common/configuration/integrations/wsgi.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.