Skip to content

Logging

brats.utils.logging

disable

disable() -> None

Disable the logging for the brats package.

Source code in brats/utils/logging.py
22
23
24
25
26
27
def disable() -> None:
    """
    Disable the logging for the brats package.
    """

    logger.disable("brats")

enable

enable() -> None

Enable the logging for the brats package.

Source code in brats/utils/logging.py
30
31
32
33
34
35
def enable() -> None:
    """
    Enable the logging for the brats package.
    """

    logger.enable("brats")

add_console_handler

add_console_handler(
    level: Union[str, int] = "WARNING",
) -> None

Add a console handler to the logger for the brats package.

Follows the singleton pattern, ensuring only one console handler is present at any time.

Parameters:

Name Type Description Default
level str | int

The logging level for the console handler. Defaults to "WARNING".

'WARNING'
Source code in brats/utils/logging.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def add_console_handler(level: Union[str, int] = "WARNING") -> None:
    """
    Add a console handler to the logger for the brats package.

    Follows the singleton pattern, ensuring only one console handler is present at any time.

    Args:
        level (str | int): The logging level for the console handler. Defaults to "WARNING".
    """
    global _console_handler_id

    with _console_handler_lock:
        if _console_handler_id is None:
            _console_handler_id = logger.add(sys.stderr, level=level)
        else:
            with suppress(ValueError):
                logger.remove(_console_handler_id)
            _console_handler_id = logger.add(sys.stderr, level=level)

remove_console_handler

remove_console_handler() -> None

Remove the console handler if it was added.

Source code in brats/utils/logging.py
58
59
60
61
62
63
64
65
66
67
68
def remove_console_handler() -> None:
    """
    Remove the console handler if it was added.
    """
    global _console_handler_id

    with _console_handler_lock:
        if _console_handler_id is not None:
            with suppress(ValueError):
                logger.remove(_console_handler_id)
            _console_handler_id = None