Skip to content

Fix italic and underline ANSI escape codes - #4184

Open
kamilkrzywanski wants to merge 2 commits into
apache:2.xfrom
kamilkrzywanski:fix/4105-ansi-italic-underline
Open

Fix italic and underline ANSI escape codes#4184
kamilkrzywanski wants to merge 2 commits into
apache:2.xfrom
kamilkrzywanski:fix/4105-ansi-italic-underline

Conversation

@kamilkrzywanski

@kamilkrzywanski kamilkrzywanski commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #4105.

AnsiEscape was missing italic (SGR 3) and had underline mapped to 3 instead of 4. After the Jansi removal, that made italic warn as invalid and underline render as italic.

Changes

  • Add ITALIC("3") and correct UNDERLINE to "4"
  • Document italic in the pattern layout style keywords
  • Add regression tests with hard-coded SGR sequences
  • Changelog entry

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify passed
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests are provided

AnsiEscape had UNDERLINE mapped to SGR 3 (italic) and no ITALIC entry.
Map italic to 3 and underline to 4, and cover both with regression tests.
@ramanathan1504

Copy link
Copy Markdown
Contributor

@kamilkrzywanski, thanks! I'll try to get this cleared whenever I find the time. Thanks for your patience.

* compare equal to itself.
* </p>
*/
class AnsiEscapeTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u extend the test case for remaining format also?

"",
"@|white key|@ = @|cyan,bold some value|@",
"\u001b[37mkey\u001b[m = \u001b[36;1msome value\u001b[m"),
// GitHub issue #4105: italic = SGR 3, underline = SGR 4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed remove the comments

"",
"@|italic italic text|@ and @|underline underlined text|@",
"\u001b[3mitalic text\u001b[m and \u001b[4munderlined text\u001b[m"),
// Return broken escapes as is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here also remove comments

@ramanathan1504 ramanathan1504 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the issue, @vy suspected AnsiEscape should also be "checked for other differences" against Jansi — that part is still open. Worth doing the full sweep: walk every constant in org.fusesource.jansi.AnsiRenderer.Code (the enum JAnsiTextRenderer.toCode used before #3070) and check it resolves in AnsiEscape. italic isn't the only casualty — try faint or blink_slow and you'll see the pattern. A quick way to check a candidate: AnsiEscape.createSequence(name) returning a bare ESC[m means the name didn't resolve, so the style silently does nothing and you get a The style attribute X is incorrect. warning on the StatusLogger.

@github-project-automation github-project-automation Bot moved this to Changes requested in Log4j pull request tracker Aug 1, 2026
Add missing AnsiRenderer.Code names (faint, blink_slow, etc.), extend
SGR mapping tests, and drop the extra test comments from review.
@kamilkrzywanski

Copy link
Copy Markdown
Contributor Author

@ramanathan1504 thanks for the review.

Did the full Jansi AnsiRenderer.Code sweep and added the missing names (faint, blink_slow, etc.). Extended the tests and removed those comments.

Should be ready for another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Changes requested

Development

Successfully merging this pull request may close these issues.

Missing ANSI Italic Style and Rendering Error in Underline Style

2 participants