Fix ANSI escape code pollution in log output (backport #2741) #2784
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is an automatic backport of pull request #2741 done by [Mergify](https://mergify.com).