ml_switcheroo.utils.console¶

Central Logging and Console Utilities.

This module unifies the application’s output mechanism using the Python standard logging library, backed by rich for formatting.

It serves two primary purposes:

  1. Standard Logging Integration: Provides a configured logging.Logger and adapter functions (log_success, log_warning) that route to standard logging channels.

  2. Environment Injection: Implements a Proxy pattern for the Rich Console. This allows the output destination (stdout, file, or in-memory buffer) to be swapped at runtime via set_console. This is critical for WebAssembly (WASM) integration, where logs must be captured and returned to the browser context.

Attributes¶

SUCCESS_LEVEL_NUM

console

Functions¶

set_console(→ None)

Global helper to inject a specific console instance.

reset_console(→ None)

Global helper to reset logging and console to standard output.

get_console(→ rich.console.Console)

Retrieves the currently active console backend.

log_info(→ None)

Logs an informational message via standard logging.

log_success(→ None)

Logs a success message via standard logging.

log_warning(→ None)

Logs a warning message via standard logging.

log_error(→ None)

Logs an error message via standard logging.

Module Contents¶

ml_switcheroo.utils.console.SUCCESS_LEVEL_NUM = 25¶
ml_switcheroo.utils.console.console¶
ml_switcheroo.utils.console.set_console(new_console: rich.console.Console) → None¶

Global helper to inject a specific console instance.

This updates both the console proxy object and the standard logging handlers to write to the new instance. Use this in Web/WASM contexts to redirect output to a capture buffer.

Parameters:

new_console (Console) – The configured Rich console to use globally.

ml_switcheroo.utils.console.reset_console() → None¶

Global helper to reset logging and console to standard output.

ml_switcheroo.utils.console.get_console() → rich.console.Console¶

Retrieves the currently active console backend.

Returns:

The active Rich Console.

Return type:

Console

ml_switcheroo.utils.console.log_info(msg: str) → None¶

Logs an informational message via standard logging.

Parameters:

msg (str) – The message content. Can include rich markup like [bold].

ml_switcheroo.utils.console.log_success(msg: str) → None¶

Logs a success message via standard logging.

Parameters:

msg (str) – The message content.

ml_switcheroo.utils.console.log_warning(msg: str) → None¶

Logs a warning message via standard logging.

Parameters:

msg (str) – The message content.

ml_switcheroo.utils.console.log_error(msg: str) → None¶

Logs an error message via standard logging.

Parameters:

msg (str) – The message content.