-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Strip ANSI escape codes from file logging #90900
Strip ANSI escape codes from file logging #90900
Conversation
8dad40e
to
3175d62
Compare
3175d62
to
12a004a
Compare
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.
Looks good.
At some point we might have to consider making RegEx a core component instead of a module, as we're starting to use it in more and more places and these conditional behaviors are error prone. (It might be the case already that a build without the regex module, while it should compile fine, might have bugs in some features that are not expected.)
Text editors cannot display ANSI escape codes, so these should be stripped from log files to ensure readability. Since this uses a regex, this works both for `print_rich()` and manually inserted ANSI escape codes. Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
12a004a
to
459f14c
Compare
Thanks! |
Text editors cannot display ANSI escape codes, so these should be stripped from log files to ensure readability.
Since this uses a regex, this works both for
print_rich()
and manually inserted ANSI escape codes.This has a slight performance impact: starting Godot, printing 200,000 lines then exiting Godot now takes 1.85 seconds instead of 1.75 seconds on an i9-13900K with a Linux x86_64 optimized (LTO) editor build. It may be possible to have a slightly faster solution using manual string handling, but handling all ANSI escape codes in a robust manner can be nontrivial. I've tried to use
strstr()
to check for the presence of an ANSI escape code in the log message before applying the regex on it, but it made no difference in performance.Preview
stdout appearance for reference:
Before
Log file contents:
After
Log file contents: