Is there any way to add more colors to Log4j2's output via log4j2.xml?

Viewed 11

I know that I can already specify ANSI colors via {style}, which as a limited set of supported colors:

The color names are ANSI names defined in the AnsiEscape class.

I would like to add additional colors that are normally available at my Linux shell to the live terminal console via log4j2.xml. Is there any way to output additional color explicitly, possibly with RGB or hex, by modifying only log4j2.xml?

I'm not concerned with portability. I tried using \e[1;34m and \e[31m, but the escape sequence doesn't pass through to the output.

1 Answers

This feature was introduced in version 2.18.0 (cf. LOG4J2-3538): you can use the specifiers #RRGGBB, FG_#RRGGBB or BG_#RRGGBB in both the %style and %highlight patterns (cf. documentation).

E.g.:

%style{Hello world!}{#abcdef}
Related