fix(bcos-action): replace print() with logging module (#6229)#6304
fix(bcos-action): replace print() with logging module (#6229)#6304crowniteto wants to merge 2 commits into
Conversation
Replace all print() calls in anchor.py with the logging module for better control over log levels, formatting, and CI/CD integration. Changes: - Add logging import and logger instance - Replace print() with logger.info/warning/error/debug - Add logging.basicConfig() with structured format - Use %-style formatting for logger (best practice) Fixes Scottcjn#6229
MolhamHamwi
left a comment
There was a problem hiding this comment.
I reviewed .github/actions/bcos-action/anchor.py and the added tests/test_p2p_blocks.py changes.
Two specific observations:
-
tests/test_p2p_blocks.pyonly containsimport pytestand is unrelated to the BCOS action logging change. If this file was accidentally carried over from another branch, dropping it would keep the PR focused and avoid adding a no-op test module. -
In
anchor.py, the HTTP error response body was previously always printed on failure, but now it is logged withlogger.debug("Response: %s", error_body)whilebasicConfigdefaults to INFO. In the GitHub Action default path this means useful node/API failure details may disappear from CI logs; considerlogger.warningorlogger.errorfor the response body, possibly with truncation if it can be large.
Positive note: replacing f-string/print output with parameterized logger calls for the success path is a good cleanup because it lets the action caller control formatting and verbosity.
I received RTC compensation for this review.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
Summary
Fixes #6229 - Replace
print()withloggingmodule in.github/actions/bcos-action/anchor.py.Changes
import loggingand module-level logger instanceprint()calls with appropriate log levels:logger.warning()logger.info()logger.info()logger.error()logger.debug()logger.warning()logging.basicConfig()with structured format at entry pointWhy
Structured logging is essential in CI/CD pipelines for:
Testing
Syntax validated with
ast.parse(). All replacements maintain the same output semantics.