diff --git a/src/cleveragents/application/container.py b/src/cleveragents/application/container.py index 4af42bb4..9c99d39a 100644 --- a/src/cleveragents/application/container.py +++ b/src/cleveragents/application/container.py @@ -880,6 +880,14 @@ def get_container() -> Container: """ global _container, _audit_subscriber_initialized if _container is None: + # Configure structlog before creating the container so that + # plugin_manager extension-point registration debug messages go to + # the Python logging infrastructure (respecting the WARNING threshold) + # rather than structlog's default PrintLoggerFactory which writes to + # stdout and pollutes machine-readable CLI output formats. + from cleveragents.config.logging import configure_structlog + + configure_structlog(log_level="WARNING") _container = Container() # Retry audit subscriber initialization on every call until it # succeeds. Previously, a failed attempt during the first diff --git a/src/cleveragents/cli/main.py b/src/cleveragents/cli/main.py index 2eb8fd82..58a3639b 100644 --- a/src/cleveragents/cli/main.py +++ b/src/cleveragents/cli/main.py @@ -307,6 +307,12 @@ def main_callback( ), ) -> None: """CleverAgents - AI-powered development assistant.""" + # Suppress debug-level logs on stdout for ALL commands so machine-readable + # output formats (json, yaml, plain) receive clean stdout. Commands that + # need verbose logging can override this after parsing --log-level flags. + from cleveragents.config.logging import configure_structlog + + configure_structlog(log_level="WARNING") _register_subcommands() @@ -659,6 +665,14 @@ def main(args: list[str] | None = None) -> int: Returns: Exit code (0 for success, non-zero for errors) """ + # Configure structlog at the earliest possible point so that debug-level + # plugin_manager logs (emitted during module import) go to stderr and not + # stdout. This ensures machine-readable output (--format json/yaml/plain) + # is not polluted with log lines. + from cleveragents.config.logging import configure_structlog + + configure_structlog(log_level="WARNING") + try: err_console = get_err_console()