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
Copy file name to clipboardExpand all lines: docs/platforms/python/integrations/logging/index.mdx
+17-1Lines changed: 17 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,22 @@ main()
54
54
-`"An exception happened"` will send the current exception from `sys.exc_info()` with the stack trace and everything to the Sentry Python SDK. If there's no exception, the current stack will be attached.
55
55
- The debug message `"I am ignored"` will not surface anywhere. To capture it, you need to lower `level` to `DEBUG` (See below).
56
56
57
+
Log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` experimental option is `True`.
58
+
59
+
```python
60
+
import logging
61
+
import sentry_sdk
62
+
63
+
sentry_sdk.init(
64
+
# ...
65
+
_experiments={
66
+
"enable_logs": True,
67
+
},
68
+
)
69
+
70
+
logging.info("I will be sent to Sentry logs")
71
+
```
72
+
57
73
## Options
58
74
59
75
To change the default behavior of the logging integration, instantiate the integration manually and pass it to Sentry's `init` function:
@@ -86,7 +102,7 @@ You can pass the following keyword arguments to `LoggingIntegration()`:
86
102
87
103
-`event_level` (default `ERROR`): The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events as long as the logger itself is set to output records of those log levels (see note below). If a value of `None` occurs, the SDK won't send log records as events.
88
104
89
-
-`sentry_logs_level` (default `INFO`): The Sentry Python SDK will capture records with a level higher than or equal to `sentry_logs_level` as logs as long as the `enable_logs` experimental option is `True`:
105
+
-`sentry_logs_level` (default `INFO`): The Sentry Python SDK will capture records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/) as long as the `enable_logs` experimental option is `True`.
-`"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.
69
69
- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`.
70
70
71
+
Loguru log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` experimental option is `True`.
72
+
73
+
```python
74
+
import sentry_sdk
75
+
from loguru import logger
76
+
77
+
sentry_sdk.init(
78
+
# ...
79
+
_experiments={
80
+
"enable_logs": True,
81
+
},
82
+
)
83
+
84
+
logger.info("I will be sent to Sentry logs")
85
+
```
86
+
71
87
### Ignoring a logger
72
88
73
89
Loggers can be noisy. You can ignore a logger by calling `ignore_logger`.
@@ -134,7 +150,7 @@ sentry_sdk.init(
134
150
135
151
-`sentry_logs_level`
136
152
137
-
The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as logs. If set to `None`, the SDK won't send records as logs.
153
+
The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/). If set to `None`, the SDK won't send records as logs.
138
154
139
155
To capture Loguru log records as Sentry logs, you must enable the experimental `enable_logs` option when initializing the SDK (regardless of the `sentry_logs_level` setting).
Copy file name to clipboardExpand all lines: platform-includes/logs/integrations/python.mdx
+76-12Lines changed: 76 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
### Python Logger Integration
1
+
### Standard library logging
2
2
3
-
Sentry automatically instruments Python loggers via its `LoggingIntegration`.
3
+
The SDK's `LoggingIntegration`instruments standard library loggers in order to send Sentry structured logs to Sentry.
4
4
5
5
```python
6
6
import sentry_sdk
@@ -9,8 +9,8 @@ import logging
9
9
sentry_sdk.init(
10
10
dsn="___PUBLIC_DSN___",
11
11
_experiments={
12
-
"enable_logs": True
13
-
}
12
+
"enable_logs": True,
13
+
},
14
14
)
15
15
16
16
# Your existing logging setup
@@ -22,7 +22,7 @@ my_logger.debug('In this example debug events will not be sent to Sentry logs. m
22
22
my_logger.info('But info events will be sent to Sentry logs. my_value=%s', my_value)
23
23
```
24
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.
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
26
27
27
```python
28
28
import sentry_sdk
@@ -61,15 +61,79 @@ from sentry_sdk.integrations.logging import SentryLogsHandler
61
61
from sentry_sdk.integrations.logging import LoggingIntegration
62
62
63
63
sentry_sdk.init(
64
-
dsn="...",
65
-
_experiments={
66
-
"enable_logs": True
67
-
},
68
-
integrations=[
69
-
LoggingIntegration(sentry_logs_level=None), # Do not monkeypatch the sentry handler
70
-
]
64
+
dsn="___PUBLIC_DSN___",
65
+
_experiments={
66
+
"enable_logs": True
67
+
},
68
+
integrations=[
69
+
LoggingIntegration(sentry_logs_level=None), # Do not monkeypatch the sentry handler
70
+
],
71
71
}
72
72
73
73
# Instead, configure the root logger to send INFO-level logs to Sentry
Loguru logs can also be automatically captured and sent to Sentry.
80
+
81
+
```python
82
+
import sentry_sdk
83
+
from loguru import logger
84
+
85
+
sentry_sdk.init(
86
+
dsn="___PUBLIC_DSN___",
87
+
_experiments={
88
+
"enable_logs": True,
89
+
},
90
+
)
91
+
92
+
loguru.debug("In this example, debug events will not be sent to Sentry logs.")
93
+
loguru.info("On the other hand, info events will be sent to Sentry logs.")
94
+
```
95
+
96
+
By default, the Loguru integration sends `INFO`-level and higher logs to Sentry logs aslongas`enable_logs`is`True`. A different threshold can be set via the `LoguruIntegration`'s `sentry_logs_level` parameter.
97
+
98
+
```python
99
+
import sentry_sdk
100
+
from loguru import logger
101
+
from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration
102
+
103
+
sentry_sdk.init(
104
+
dsn="___PUBLIC_DSN___",
105
+
_experiments={
106
+
"enable_logs": True
107
+
},
108
+
integrations=[
109
+
# Only send WARNING (and higher) logs to Sentry logs
logger.info("This INFO log won't be sent to Sentry logs.")
115
+
logger.warning("This WARNING log will be sent to Sentry logs.")
116
+
```
117
+
118
+
If you want other logging integrations to send logs to Sentry logs, but not Loguru, setting `sentry_logs_level` to `None` on the integration level will stop the Loguru integration for capturing Sentry logs.
119
+
120
+
```python
121
+
122
+
import sentry_sdk
123
+
from loguru import logger
124
+
from sentry_sdk.integrations.loguru import LoguruIntegration
125
+
126
+
sentry_sdk.init(
127
+
dsn="___PUBLIC_DSN___",
128
+
_experiments={
129
+
# In general, we want to capture logs as Sentry logs...
130
+
"enable_logs": True,
131
+
},
132
+
integrations=[
133
+
# ...just not from Loguru
134
+
LoguruIntegration(sentry_logs_level=None),
135
+
]
136
+
)
137
+
138
+
loguru.error("This won't be sent to Sentry logs.")
0 commit comments