Skip to content

Route package diagnostics through the logging module#24

Open
thc1006 wants to merge 2 commits into
developfrom
enh/logging-instrumentation
Open

Route package diagnostics through the logging module#24
thc1006 wants to merge 2 commits into
developfrom
enh/logging-instrumentation

Conversation

@thc1006
Copy link
Copy Markdown
Member

@thc1006 thc1006 commented May 18, 2026

Route the package's bare print() diagnostics through the standard logging module so verbosity is controllable: quiet during scoring or CI, verbose when debugging. Implements the logging instrumentation thread of #14.

What changed

  • balloon_world.py and evaluate.py each get a module logger (logging.getLogger(__name__)).
  • balloon_world.py: the two env termination messages become logger.info, and the close() trace becomes logger.debug.
  • evaluate.py: evaluate_scenario's two result lines become logger.info (lazy %s formatting). The function now also returns info["popped_count"], so library callers get the result, since the diagnostics are silent unless the caller configures logging. The __main__ entry point calls logging.basicConfig(level=INFO, stream=sys.stdout) so running python evaluate.py <cfg> still prints results to stdout.
  • The two example callers, doc/examples/run_env_agent.py and the Colab notebook, now display the returned reward.
  • New tests/test_logging.py: an AST invariant that fails if a bare print() reappears in the package.
  • New tests/test_evaluate.py: pins evaluate_scenario's return contract.

Behaviour

Reward computation and env logic are unchanged. Env diagnostics are silent by default (the consumer opts in via logging); evaluate_scenario's result is available both as a return value and, on the script and configured-logging paths, as log output.

The logger uses getLogger(__name__), so a consumer can control the whole package with logging.getLogger("BalloonPoppingGymEnv"). This minimal, standard setup composes with any later logging integration.

About #14

#14 covered three areas: functional test coverage, logging instrumentation, and a coverage CI workflow. CI and coverage are handled by #21 (PR #23); logging is this PR.

Verified

  • TDD: test_logging.py started red (5 print() offenders) and went green after the change. test_evaluate.py started red (evaluate_scenario returned None) and went green after.
  • ruff check and ruff format --check pass; the full test suite passes (11 tests).
  • The Colab evaluation path was run end to end in a fresh submodule-based environment: evaluate_scenario returns a real count and the notebook prints Total reward.

Closes #14

balloon_world.py and evaluate.py emitted diagnostics with bare
print(), which cannot be silenced for scoring or CI runs. Replace
them with per-module loggers: env termination messages at info
level, the close() trace at debug. evaluate_scenario's result lines
also become info logs, and the script entry point calls
logging.basicConfig so command-line runs still show them.

Add tests/test_logging.py, an AST invariant that fails if bare
print() reappears in the package sources.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 00:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Routes the package's bare print() diagnostics through the standard logging module so verbosity is controllable (quiet in scoring/CI, verbose when debugging), and adds an AST-based test to prevent regressions.

Changes:

  • Add module loggers in balloon_world.py and evaluate.py; replace print() calls with logger.info / logger.debug.
  • Configure logging.basicConfig(level=INFO) in evaluate.py's __main__ block to preserve CLI output.
  • Add tests/test_logging.py AST invariant that fails if any bare print() reappears in the package.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
BalloonPoppingGymEnv/envs/balloon_world.py Replace three print() diagnostics with module logger calls (info/debug).
BalloonPoppingGymEnv/evaluation/evaluate.py Replace two CLI prints with lazy-formatted logger.info; add basicConfig only in __main__.
tests/test_logging.py New AST test enforcing no bare print() in the package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

evaluate_scenario logged its result through logging but returned
None. Library callers (the Colab example, run_env_agent.py) thus
lost all visible output once the print() calls became logger
calls, since the __main__ logging.basicConfig only covers the
script path.

Return info["popped_count"] so callers receive the result, and
update the Colab notebook and run_env_agent.py to display it. The
script entry point's basicConfig now targets stdout to match the
old print() behaviour. Add tests/test_evaluate.py to pin the
return contract.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@thc1006 thc1006 requested a review from William-Mou May 18, 2026 20:52
@thc1006 thc1006 self-assigned this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants