Files
tracer-cloud--opensre/platform/observability/render/debug.py
T
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

55 lines
1.7 KiB
Python

"""Debug-print port — plain default + injection for richer adapters.
Core call sites do ``debug_print("...")`` unconditionally. The default
implementation prints to stdout only when ``TRACER_VERBOSE`` is set,
matching how the legacy CLI helper behaved in non-rich mode.
The REPL boundary can register a Rich-styled adapter via
:func:`set_debug_printer` so debug output threads through the
persistent input frame instead of landing as raw text below it.
"""
from __future__ import annotations
import os
import sys
from collections.abc import Callable
DebugPrinter = Callable[[str], None]
def _verbose_env_set() -> bool:
"""True iff ``TRACER_VERBOSE`` indicates the user wants debug output.
Kept narrow on purpose: the legacy helper also consulted the
interactive-shell's data-store (``is_debug``/``is_verbose``); pulling
that in would re-introduce the CLI dependency we're refactoring
out of core. Adapters that want richer gating can register their
own printer that checks additional state.
"""
return os.getenv("TRACER_VERBOSE", "").lower() in ("1", "true", "yes")
def _default_debug_printer(message: str) -> None:
if not _verbose_env_set():
return
print(f"DEBUG: {message}", file=sys.stderr)
_printer: DebugPrinter = _default_debug_printer
def debug_print(message: str) -> None:
"""Emit a debug message via the registered printer."""
_printer(message)
def set_debug_printer(printer: DebugPrinter) -> None:
"""Install ``printer`` as the active debug-print implementation.
Boundary code (typically the CLI start-up) calls this to wire a
Rich/REPL-aware printer in place of the stderr default.
"""
global _printer
_printer = printer