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 th
(message, category, filename, lineno, file=None, line=None)
| 2230 | _warnings_showwarning = None |
| 2231 | |
| 2232 | def _showwarning(message, category, filename, lineno, file=None, line=None): |
| 2233 | """ |
| 2234 | Implementation of showwarnings which redirects to logging, which will first |
| 2235 | check to see if the file parameter is None. If a file is specified, it will |
| 2236 | delegate to the original warnings implementation of showwarning. Otherwise, |
| 2237 | it will call warnings.formatwarning and will log the resulting string to a |
| 2238 | warnings logger named "py.warnings" with level logging.WARNING. |
| 2239 | """ |
| 2240 | if file is not None: |
| 2241 | if _warnings_showwarning is not None: |
| 2242 | _warnings_showwarning(message, category, filename, lineno, file, line) |
| 2243 | else: |
| 2244 | s = warnings.formatwarning(message, category, filename, lineno, line) |
| 2245 | logger = getLogger("py.warnings") |
| 2246 | if not logger.handlers: |
| 2247 | logger.addHandler(NullHandler()) |
| 2248 | # bpo-46557: Log str(s) as msg instead of logger.warning("%s", s) |
| 2249 | # since some log aggregation tools group logs by the msg arg |
| 2250 | logger.warning(str(s)) |
| 2251 | |
| 2252 | def captureWarnings(capture): |
| 2253 | """ |
nothing calls this directly
no test coverage detected