|
1 | 1 | import logging
|
| 2 | +import sys |
2 | 3 | from datetime import datetime, timezone
|
3 | 4 | from fnmatch import fnmatch
|
4 | 5 |
|
@@ -248,27 +249,25 @@ def _emit(self, record):
|
248 | 249 | event["level"] = level # type: ignore[typeddict-item]
|
249 | 250 | event["logger"] = record.name
|
250 | 251 |
|
251 |
| - # Log records from `warnings` module as separate issues |
252 |
| - record_captured_from_warnings_module = ( |
253 |
| - record.name == "py.warnings" and record.msg == "%s" |
254 |
| - ) |
255 |
| - if record_captured_from_warnings_module: |
256 |
| - # use the actual message and not "%s" as the message |
257 |
| - # this prevents grouping all warnings under one "%s" issue |
258 |
| - msg = record.args[0] # type: ignore |
259 |
| - |
260 |
| - event["logentry"] = { |
261 |
| - "message": msg, |
262 |
| - "formatted": record.getMessage(), |
263 |
| - "params": (), |
264 |
| - } |
265 |
| - |
| 252 | + if ( |
| 253 | + sys.version_info < (3, 11) |
| 254 | + and record.name == "py.warnings" |
| 255 | + and record.msg == "%s" |
| 256 | + ): |
| 257 | + # warnings module on Python 3.10 and below sets record.msg to "%s" |
| 258 | + # and record.args[0] to the actual warning message. |
| 259 | + # This was fixed in https://github.com/python/cpython/pull/30975. |
| 260 | + message = record.args[0] |
| 261 | + params = () |
266 | 262 | else:
|
267 |
| - event["logentry"] = { |
268 |
| - "formatted": record.getMessage(), |
269 |
| - "message": to_string(record.msg), |
270 |
| - "params": record.args, |
271 |
| - } |
| 263 | + message = record.msg |
| 264 | + params = record.args |
| 265 | + |
| 266 | + event["logentry"] = { |
| 267 | + "message": to_string(message), |
| 268 | + "formatted": record.getMessage(), |
| 269 | + "params": params, |
| 270 | + } |
272 | 271 |
|
273 | 272 | event["extra"] = self._extra_from_record(record)
|
274 | 273 |
|
|
0 commit comments