You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Copy file name to clipboardExpand all lines: platform-includes/logs/integrations/python.mdx
+37-5Lines changed: 37 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,20 +7,52 @@ import sentry_sdk
7
7
import logging
8
8
9
9
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
+
}
14
14
)
15
15
16
16
# Your existing logging setup
17
-
my_logger = logging.Logger("some-logger")
17
+
my_logger = logging.getLogger(__name__)
18
+
my_logger.setLevel(logging.INFO)
18
19
19
20
my_value =42
20
21
my_logger.debug('In this example debug events will not be sent to Sentry logs. my_value=%s', my_value)
21
22
my_logger.info('But info events will be sent to Sentry logs. my_value=%s', my_value)
22
23
```
23
24
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,
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
+
24
56
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:
0 commit comments