On this page
  1. logging.captureWarnings
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

logging.captureWarnings

Prev: logging.BufferingFormatter | Up: logging | Next: logging.critical
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.critical
Ref: docs.python.org — logging.captureWarnings
Tags: #public #python3 #stdlib #logging


Import

import logging
from logging import captureWarnings

Signature & Overview

logging.captureWarnings(capture)

If capture is true, redirect all warnings to the logging package.

Usage

import logging
import warnings

logging.captureWarnings(True)
try:
    # warnings.warn(...) is now routed to the "py.warnings" logger
    assert logging.getLogger("py.warnings") is not None
finally:
    logging.captureWarnings(False)

Gotchas

REPL Inspect

from logging import captureWarnings
help(captureWarnings)

Linked from

Related notes