Skip to content

Commit e5e0be7

Browse files
szokeasaurusrexantonpirker
authored andcommitted
docs(python): Mention logger log level is respected for logs (#13830)
## DESCRIBE YOUR PR Clarify that the Logging Integration respects the logger's configured log level when using Sentry logs. Fixes #13829 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 1425af3 commit e5e0be7

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

platform-includes/logs/integrations/python.mdx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,52 @@ import sentry_sdk
77
import logging
88

99
sentry_sdk.init(
10-
dsn="___PUBLIC_DSN___",
11-
_experiments={
12-
"enable_logs": True
13-
}
10+
dsn="___PUBLIC_DSN___",
11+
_experiments={
12+
"enable_logs": True
13+
}
1414
)
1515

1616
# Your existing logging setup
17-
my_logger = logging.Logger("some-logger")
17+
my_logger = logging.getLogger(__name__)
18+
my_logger.setLevel(logging.INFO)
1819

1920
my_value = 42
2021
my_logger.debug('In this example debug events will not be sent to Sentry logs. my_value=%s', my_value)
2122
my_logger.info('But info events will be sent to Sentry logs. my_value=%s', my_value)
2223
```
2324

25+
By default, the logging integration sends INFO-level logs and higher to Sentry logs. You can set a different threshold via the `LoggingIntegration`'s `sentry_logs_level` parameter. However, regardless of the `sentry_logs_level` setting, the SDK only sends logs if they are at or above the logger's level.
26+
27+
```python
28+
import sentry_sdk
29+
import logging
30+
from sentry_sdk.integrations.logging import LoggingIntegration
31+
32+
sentry_sdk.init(
33+
dsn="___PUBLIC_DSN___",
34+
_experiments={
35+
"enable_logs": True
36+
},
37+
integrations=[
38+
# Only send WARNING (and higher) logs to Sentry logs,
39+
# even if the logger is set to a lower level.
40+
LoggingIntegration(sentry_logs_level=logging.WARNING),
41+
]
42+
)
43+
44+
my_logger = logging.getLogger(__name__)
45+
my_logger.setLevel(logging.INFO)
46+
47+
my_value = 42
48+
my_logger.info('This will not be sent to Sentry logs, even though the logger is set to INFO. my_value=%s', my_value)
49+
my_logger.warning('This will be sent to Sentry logs. my_value=%s', my_value)
50+
51+
my_logger.setLevel(logging.ERROR)
52+
my_logger.warning('Now, this log message will not be sent to Sentry logs, since the logger is set to ERROR.')
53+
```
54+
55+
2456
The logging integration automatically monkeypatches a handler into all loggers except for the root logger. If you'd like to manually configure the handler, you can do that like so:
2557

2658
```python

0 commit comments

Comments
 (0)