FloodAdaptLogging

FloodAdaptLogging(
    self,
    file_path: Optional[Path] = None,
    loglevel_console: int = logging.WARNING,
    loglevel_root: int = logging.INFO,
    loglevel_files: int = logging.DEBUG,
    formatter: logging.Formatter = _DEFAULT_FORMATTER,
    ignore_warnings: Optional[list[type[Warning]]] = None,
)

Methods

Name Description
add_file_handler Add a file handler to the logger that directs outputs to a the file.
close_files Close all file handlers except those in the exclude list.
configure_warnings Configure the behavior of Python warnings.
deprecation_warning Log a deprecation warning with reason and the version that will remove it.
getLogger Get a logger with the specified name. If no name is provided, return the root logger.
remove_file_handler Remove a file handler from the logger, which stops sending logs to that file and closes it.
to_file Open a file at filepath to write logs to. Does not affect other loggers.

add_file_handler

FloodAdaptLogging.add_file_handler(
    file_path: Path,
    loglevel: int = logging.DEBUG,
    formatter: Optional[logging.Formatter] = None,
)

Add a file handler to the logger that directs outputs to a the file.

close_files

FloodAdaptLogging.close_files(exclude: List[Path] = [])

Close all file handlers except those in the exclude list.

configure_warnings

FloodAdaptLogging.configure_warnings(
    action: str = 'default',
    category: Optional[type[Warning]] = None,
)

Configure the behavior of Python warnings.

Parameters

action : str = 'default'

The action to take on warnings. Common actions include ‘ignore’, ‘default’, ‘error’, ‘always’, etc. The default is ‘default’, which shows warnings once per triggering location.

category : type[Warning] = None

The category of warnings to configure. If not provided, all warnings are configured. categories include DeprecationWarning, UserWarning, RuntimeWarning, etc.

deprecation_warning

FloodAdaptLogging.deprecation_warning(version: str, reason: str)

Log a deprecation warning with reason and the version that will remove it.

getLogger

FloodAdaptLogging.getLogger(
    name: Optional[str] = None,
    level: int = logging.INFO,
)

Get a logger with the specified name. If no name is provided, return the root logger.

If the logger does not exist, it is created with the specified level.

Parameters

name : str = None

The name of the logger. If not provided, the root logger is returned.

level : (int,) = logging.INFO

The level of the logger. The default is logging.INFO.

Returns

: logging.Logger

The logger with the specified name.

remove_file_handler

FloodAdaptLogging.remove_file_handler(file_path: Path)

Remove a file handler from the logger, which stops sending logs to that file and closes it.

to_file

FloodAdaptLogging.to_file(
    file_path: Path,
    loglevel: int = logging.DEBUG,
    formatter: logging.Formatter = _DEFAULT_FORMATTER,
)

Open a file at filepath to write logs to. Does not affect other loggers.

When the context manager exits (via regular execution or an exception), the file is closed and the handler is removed.

Back to top