Skip to content

Refactor Pretty control sequence escaping#3483

Open
LHolten wants to merge 6 commits intotokio-rs:mainfrom
LHolten:push-rwwyxtmlnswn
Open

Refactor Pretty control sequence escaping#3483
LHolten wants to merge 6 commits intotokio-rs:mainfrom
LHolten:push-rwwyxtmlnswn

Conversation

@LHolten
Copy link

@LHolten LHolten commented Feb 25, 2026

Motivation

The Pretty formatter was applying escaping to control characters, but only for the message field and errors.
Another issue is that the escaped control characters often make the message field unreadable because of colour codes #3369.

Solution

First, this PR fixes the Pretty formatter to apply escaping consistently to all fields (the DefaultFields formatter seems to also skip escaping some field, but I did not want to fix it).

It also changes the escaping on the message field specifically to remove CSI codes entirely instead of just escaping them. While this doesn't fix #3369 entirely, it makes the problem a bit less bad, because now you can at least read the message.
This solution does not make any changes to the public API, because I do not know what the best solution is to solving the trusted control characters problem.

@LHolten LHolten requested review from a team, hawkw and hds as code owners February 25, 2026 11:46
@LHolten
Copy link
Author

LHolten commented Feb 25, 2026

I just realized that this doesn't help with the ansi colour codes at all, because those are normal characters after the escape character. I will update this PR with a better implementation to skip the colour codes.

@LHolten LHolten changed the title Refactor Pretty control sequence escaping WIP: Refactor Pretty control sequence escaping Feb 25, 2026
@LHolten LHolten changed the title WIP: Refactor Pretty control sequence escaping Refactor Pretty control sequence escaping Feb 25, 2026
@LHolten
Copy link
Author

LHolten commented Feb 25, 2026

I just realized that this doesn't help with the ansii colour codes at all, because those are normal characters after the escape character. I will update this PR with a better implementation to skip the colour codes.

Fixed and added a test.

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.

Regression: New tracing-subscriber breaks ANSI color and styling support

1 participant