-
Notifications
You must be signed in to change notification settings - Fork 377
Fix ANSI escape code pollution in log output #2741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Make bcolors class environment-aware to respect RCUTILS_COLORIZED_OUTPUT - Remove ANSI codes from all logger calls in controller_manager_services.py - Remove ANSI codes from logger calls in spawner.py and hardware_spawner.py - Maintain backward compatibility with existing bcolors usage - Fixes Issue ros-controls#2592: Option for uncolored log output Environment variable behavior: - RCUTILS_COLORIZED_OUTPUT=0: No colors in output - RCUTILS_COLORIZED_OUTPUT=1: Colors enabled - Unset: Auto-detect TTY for color support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to bcolors class look fine, but can't we still keep that in the rclpy logging? You removed it without an alternative.
controller_manager/controller_manager/controller_manager_services.py
Outdated
Show resolved
Hide resolved
- Add _color_enabled() function that respects RCUTILS_COLORIZED_OUTPUT - Make bcolors class environment-aware using _color_enabled() - Remove redundant COLOR_ENABLED variable for cleaner implementation - Add bcolors import to spawner.py and hardware_spawner.py - Fixes ANSI escape code pollution in CI logs while preserving colors in interactive terminals Resolves: ros-controls#2592
7290f6a to
eb90d06
Compare
|
Hey @christophfroehlich can you take a look at my changes and let me know if I have to change anything else, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2741 +/- ##
==========================================
- Coverage 89.60% 89.60% -0.01%
==========================================
Files 152 152
Lines 17637 17645 +8
Branches 1448 1450 +2
==========================================
+ Hits 15804 15811 +7
Misses 1250 1250
- Partials 583 584 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locally tested, and the log files are much cleaner now.
Still, I'd like anyone else to test this if the colored output isn't broken where it should not be.
In the meantime, please add a simple note to the release_notes and to the docs, maybe in the helper scripts section.
- Document color output handling in userdoc.rst - Add release note about bcolors respecting RCUTILS_COLORIZED_OUTPUT
8a3faf3 to
694c486
Compare
|
This pull request is in conflict. Could you fix it @saumanraaj? |
|
I added some helper notes and a note in the release notes. Let me know if I have to change anything, will do thanks |
|
Please don't do force pushes, as this is hard for reviewers to track what has changed since the last commit. I now have to test everything again.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix pre-commit and rst issues.
|
I tried fixing most of the pre-commit and rst issues. It looks fine for me locally. If the CI logs fail again will fix them accordingly, thanks. |
|
Hey @christophfroehlich, this PR only touches Python (controller_manager_services.py, spawner.py, hardware_spawner.py) and docs (RST). No C++/controller logic was changed. |

Pull Request description:
Fix ANSI Escape Code Pollution - Environment-Aware
bcolorsSummary
This PR fixes Issue #2592 by making the existing
bcolorsclass environment-aware, ensuring that ANSI escape codes do not pollute ROS logs while maintaining backward compatibility.Changes Made
Made the
bcolorsclass respect theRCUTILS_COLORIZED_OUTPUTenvironment variable.Automatically detect whether output is a TTY to enable/disable colors intelligently.
Removed all ANSI codes from logger calls in:
controller_manager_services.pyspawner.pyhardware_spawner.pyRetained
bcolorsusage across the codebase to avoid breaking existing behavior.Environment Variable Behavior
Testing and Verification
Verified that logs are now clean and contain no escape codes.
Confirmed that CLI output remains colorized when applicable.
Verified backward compatibility with existing code paths.
Ran
pre-commitchecks (Python hooks passed;Checklist
Limited scope: focuses solely on Issue Option for uncolored log output #2592
Descriptive commit message and PR title
CI expected to pass
Logger outputs verified to be ANSI-free
Manual tests confirm correct color behavior
Contributing Notes
Before submitting PRs:
Keep PRs focused on a single issue or feature.
Use clear, descriptive titles and concise summaries.
Ensure the CI pipeline passes.
Request reviews from maintainers when ready.
Add or update tests where applicable.