Terminal Logger¶

Click-backed terminal output for the Patcher logger.

This module is the CLI’s adapter onto patcher.core.logger.PatcherLog. Installing a TerminalHandler adds colored level-prefixed output on top of the always-present rotating file handler; library users who never import patcher.cli get the file-only behavior with no asyncclick dependency.

Two install points:

class TerminalHandler(level=0)[source]¶

Logging handler that emits records as Rich-styled lines on stdout.

Maps each log level to a color so a debug run produces the same visual output the legacy in-class click.echo calls did (magenta DEBUG, blue INFO, bold-yellow WARNING, bold-red ERROR). The leading \r preserves the existing behavior of overwriting the current terminal line. Output routes through the shared console.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

emit(record: LogRecord) None[source]¶

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (LogRecord)

Return type:

None

install_terminal_handler(debug: bool) None[source]¶

Attach a TerminalHandler to the Patcher logger when in debug mode.

Idempotent. Calling twice will not add duplicate handlers. No-op when debug is False, so the standard CLI run (and any library import path) sees no terminal output beyond what callers explicitly emit.

Parameters:

debug (bool) – Whether the CLI was invoked with --debug.

Return type:

None

install_terminal_excepthook() None[source]¶

Chain a terminal-styled excepthook onto custom_excepthook().

The core hook logs unhandled exceptions to file. This wrapper additionally emits a one-line red error message and a hint about the log file to stderr, matching the legacy in-module behavior. Library callers who never import patcher.cli are unaffected; their sys.excepthook is not touched.

Return type:

None