apache / apache/logging-log4j2

Predefined ANSI styles (Style=Spock, Style=Kirk) never apply

Open Beginner friendly
#4,254 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

`%xEx{ansi(Style=Spock)}` and `%xEx{ansi(Style=Kirk)}` render with no styling at all.

Two defects in `JAnsiTextRenderer`:

1. `JAnsiTextRenderer.java:217` — the predefined map is merged with `map.putAll(predefinedMap)`,
which keeps its keys as written (`Name`, `Message`, …), but lookup at line 247 is
`styleMap.get(toRootUpperCase(styleName))`, so nothing ever matches. The name falls through to
`AnsiEscape.createSequence("Name")`, which warns and returns an empty `ESC[m`.
2. `JAnsiTextRenderer.java:97-101` — `entry()` builds `CSI + code + code` with no `;` separator
and no `m` suffix, so `entry("Name", BG_RED, WHITE)` yields `ESC[4137`. `merge()` at line 263
then strips a trailing `m` that was never appended. Masked today by (1).

Reproduced against `2.x` HEAD, `new JAnsiTextRenderer(new String[] {"ansi", "Style=Spock"}, emptyMap())`:

Name -> ESC[m XYZ ESC[m
Name,Message -> ESC[;m XYZ ESC[m
bg_red,white -> ESC[41;37m XYZ ESC[m (user-supplied styles are fine)

`main` has both defects in the renamed `AnsiTextRenderer` (lines 192, 96-99, 238).

Found while reviewing #4184; unrelated to that PR.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported locations in JAnsiTextRenderer.java, especially entry(), the predefined-style map merge, lookup, and merge(); compare them with the renamed AnsiTextRenderer in main. Reproduce using the shown Style=Spock constructor and verify that Spock and Kirk produce styled ANSI sequences while user-supplied styles remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.