Class JAnsiTextRenderer

java.lang.Object
org.apache.logging.log4j.core.pattern.JAnsiTextRenderer
All Implemented Interfaces:
TextRenderer

public final class JAnsiTextRenderer extends Object implements TextRenderer
Renders an input as ANSI escaped output.

Uses the JLine AnsiRenderer syntax to render a message into an ANSI escaped string.

The default syntax for embedded ANSI codes is:

   @|code(,code)* text|@
 
For example, to render the message "Hello" in green, use:
   @|green Hello|@
 
To render the message "Hello" in bold and red, use:
   @|bold,red Warning!|@
 
You can also define custom style names in the configuration with the syntax:
 %message{ansi}{StyleName=value(,value)*( StyleName=value(,value)*)*}%n
 
For example:
 %message{ansi}{WarningStyle=red,bold KeyStyle=white ValueStyle=blue}%n
 
The call site can look like this:
 logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());
 

Note: this class was originally copied and then heavily modified from JAnsi/JLine AnsiRenderer, licensed under an Apache Software License, version 2.0.