Implementation of showwarnings which redirects to logging, which will first check to see if the file parameter is None. If a file is specified, it will delegate to the original warnings implementation of showwarning. Otherwise, it will call warnings.formatwarning and will log the re
(message, category, filename, lineno, file=None, line=None)
| 2311 | _warnings_showwarning = None |
| 2312 | |
| 2313 | def _showwarning(message, category, filename, lineno, file=None, line=None): |
| 2314 | """ |
| 2315 | Implementation of showwarnings which redirects to logging, which will first |
| 2316 | check to see if the file parameter is None. If a file is specified, it will |
| 2317 | delegate to the original warnings implementation of showwarning. Otherwise, |
| 2318 | it will call warnings.formatwarning and will log the resulting string to a |
| 2319 | warnings logger named "py.warnings" with level logging.WARNING. |
| 2320 | """ |
| 2321 | if file is not None: |
| 2322 | if _warnings_showwarning is not None: |
| 2323 | _warnings_showwarning(message, category, filename, lineno, file, line) |
| 2324 | else: |
| 2325 | s = warnings.formatwarning(message, category, filename, lineno, line) |
| 2326 | logger = getLogger("py.warnings") |
| 2327 | if not logger.handlers: |
| 2328 | logger.addHandler(NullHandler()) |
| 2329 | # bpo-46557: Log str(s) as msg instead of logger.warning("%s", s) |
| 2330 | # since some log aggregation tools group logs by the msg arg |
| 2331 | logger.warning(str(s)) |
| 2332 | |
| 2333 | def captureWarnings(capture): |
| 2334 | """ |
nothing calls this directly
no test coverage detected
searching dependent graphs…