Files
falyx/falyx/debug.py
Roland Thomas cce92cca09 refactor: align routing internals and refresh framework docstrings
- rename several Falyx and Command internal helpers with leading underscores
- rename parallel terminology to concurrent across ActionGroup and SharedContext
- update completer and routing references to match current routed API names
- add and revise module, class, and method docstrings across core modules
- refresh package copyright headers for 2026
2026-04-13 18:46:33 -04:00

57 lines
2.0 KiB
Python

# Falyx CLI Framework — (c) 2026 rtj.dev LLC — MIT Licensed
"""Provides debug logging hooks for Falyx action execution.
This module defines lifecycle hook functions (`log_before`, `log_success`, `log_after`, `log_error`)
that can be registered with a `HookManager` to trace command execution.
Logs include:
- Action invocation with argument signature
- Success result (with truncation for large outputs)
- Errors with full exception info
- Total runtime duration after execution
Also exports `register_debug_hooks()` to register all log hooks in bulk.
"""
from falyx.context import ExecutionContext
from falyx.hook_manager import HookManager, HookType
from falyx.logger import logger
def log_before(context: ExecutionContext):
"""Log the start of an action."""
args = ", ".join(map(repr, context.args))
kwargs = ", ".join(f"{key}={value!r}" for key, value in context.kwargs.items())
signature = ", ".join(filter(None, [args, kwargs]))
logger.info("[%s] Starting -> %s(%s)", context.name, context.action, signature)
def log_success(context: ExecutionContext):
"""Log the successful completion of an action."""
result_str = repr(context.result)
if len(result_str) > 100:
result_str = f"{result_str[:100]} ..."
logger.debug("[%s] Success -> Result: %s", context.name, result_str)
def log_after(context: ExecutionContext):
"""Log the completion of an action, regardless of success or failure."""
logger.debug("[%s] Finished in %.3fs", context.name, context.duration)
def log_error(context: ExecutionContext):
"""Log an error that occurred during the action."""
logger.error(
"[%s] Error (%s): %s",
context.name,
type(context.exception).__name__,
context.exception,
exc_info=True,
)
def register_debug_hooks(hooks: HookManager):
hooks.register(HookType.BEFORE, log_before)
hooks.register(HookType.AFTER, log_after)
hooks.register(HookType.ON_SUCCESS, log_success)
hooks.register(HookType.ON_ERROR, log_error)