Skip to content

logging_helper

Deprecated alias for :mod:clabe.logging.

clabe.logging_helper was renamed to :mod:clabe.logging. This module re-exports the same public names so existing imports keep working, but emits a :class:DeprecationWarning on import. Update from clabe.logging_helper import ... (or clabe.logging_helper.x) to clabe.logging — this alias will be removed in a future release.

add_file_handler

add_file_handler(
    logger: TLogger, output_path: PathLike
) -> TLogger

Adds a file handler to the logger to write logs to a file.

Creates a new file handler with UTC timezone formatting and adds it to the specified logger for persistent log storage.

Parameters:

Name Type Description Default
logger TLogger

The logger to which the file handler will be added

required
output_path PathLike

The path to the log file

required

Returns:

Name Type Description
TLogger TLogger

The logger with the added file handler

Source code in src/clabe/logging/_stdlib.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def add_file_handler(logger: TLogger, output_path: os.PathLike) -> TLogger:
    """
    Adds a file handler to the logger to write logs to a file.

    Creates a new file handler with UTC timezone formatting and adds it to the
    specified logger for persistent log storage.

    Args:
        logger: The logger to which the file handler will be added
        output_path: The path to the log file

    Returns:
        TLogger: The logger with the added file handler
    """
    file_handler = logging.FileHandler(Path(output_path), encoding="utf-8", mode="w")
    file_handler.setFormatter(utc_formatter)
    logger.addHandler(file_handler)
    return logger

close_file_handlers

close_file_handlers(logger: TLogger) -> TLogger

Closes all file handlers associated with the logger.

Iterates through all handlers associated with the logger and closes any file handlers to ensure proper resource cleanup.

Parameters:

Name Type Description Default
logger TLogger

The logger whose file handlers will be closed

required

Returns:

Name Type Description
TLogger TLogger

The logger with closed file handlers

Source code in src/clabe/logging/_stdlib.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def close_file_handlers(logger: TLogger) -> TLogger:
    """
    Closes all file handlers associated with the logger.

    Iterates through all handlers associated with the logger and closes any
    file handlers to ensure proper resource cleanup.

    Args:
        logger: The logger whose file handlers will be closed

    Returns:
        TLogger: The logger with closed file handlers
    """
    for handler in logger.handlers:
        if isinstance(handler, logging.FileHandler):
            handler.close()
    return logger

configure_console_logging

configure_console_logging() -> None

Installs clabe's default root-logger configuration (console handler, format, level).

Source code in src/clabe/logging/_stdlib.py
 98
 99
100
101
102
def configure_console_logging() -> None:
    """
    Installs clabe's default root-logger configuration (console handler, format, level).
    """
    logging.basicConfig(level=logging.INFO, format=log_fmt, datefmt=datetime_fmt, handlers=[rich_handler])

set_console_level

set_console_level(level: int) -> None

Sets the verbosity threshold of the interactive console log handler.

This only affects what is shown to the user on the console; it is fully decoupled from what is written to the log file (see add_file_handler) and from any remote handlers.

Parameters:

Name Type Description Default
level int

A standard logging level (e.g. logging.INFO).

required
Source code in src/clabe/logging/_stdlib.py
105
106
107
108
109
110
111
112
113
114
115
116
def set_console_level(level: int) -> None:
    """
    Sets the verbosity threshold of the interactive console log handler.

    This only affects what is shown to the user on the console; it is fully
    decoupled from what is written to the log file (see ``add_file_handler``)
    and from any remote handlers.

    Args:
        level: A standard ``logging`` level (e.g. ``logging.INFO``).
    """
    rich_handler.setLevel(level)

shutdown_logger

shutdown_logger(logger: TLogger) -> TLogger

Shuts down the logger by closing all file handlers and calling logging.shutdown().

Performs a complete shutdown of the logging system, ensuring all file handlers are properly closed and resources are released.

Parameters:

Name Type Description Default
logger TLogger

The logger to shut down

required

Returns:

Name Type Description
TLogger TLogger

The logger with closed file handlers

Source code in src/clabe/logging/_stdlib.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def shutdown_logger(logger: TLogger) -> TLogger:
    """
    Shuts down the logger by closing all file handlers and calling logging.shutdown().

    Performs a complete shutdown of the logging system, ensuring all file handlers
    are properly closed and resources are released.

    Args:
        logger: The logger to shut down

    Returns:
        TLogger: The logger with closed file handlers
    """
    close_file_handlers(logger)
    logging.shutdown()
    return logger