Class JAnsiTextRenderer
java.lang.Object
org.apache.logging.log4j.core.pattern.JAnsiTextRenderer
- All Implemented Interfaces:
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionentry(String name, AnsiEscape... codes) private static voidmerge(String escapeSequence, StringBuilder output, boolean first) voidrender(StringBuilder input, StringBuilder output) Renders input text to an output.voidrender(String input, StringBuilder output, String styleName) Renders input text to an output.private voidrender(String input, StringBuilder output, String... styleNames) Renders the given input with the given names which can be ANSI code names or Log4j style names.toString()
-
Field Details
-
LOGGER
-
DefaultExceptionStyleMap
-
DEFAULT_MESSAGE_STYLE_MAP
-
PREFEDINED_STYLE_MAPS
-
BEGIN_TOKEN
- See Also:
-
END_TOKEN
- See Also:
-
CSI_LENGTH
private static final int CSI_LENGTH- See Also:
-
beginToken
-
beginTokenLen
private final int beginTokenLen -
endToken
-
endTokenLen
private final int endTokenLen -
styleMap
-
-
Constructor Details
-
JAnsiTextRenderer
-
-
Method Details
-
entry
-
ofEntries
-
render
Renders the given input with the given names which can be ANSI code names or Log4j style names.- Parameters:
input- The input to renderstyleNames- ANSI code names or Log4j style names.
-
merge
-
render
public void render(String input, StringBuilder output, String styleName) throws IllegalArgumentException Description copied from interface:TextRendererRenders input text to an output.- Specified by:
renderin interfaceTextRenderer- Parameters:
input- The inputoutput- The outputstyleName- The style name to use to render the input on the output.- Throws:
IllegalArgumentException
-
render
Description copied from interface:TextRendererRenders input text to an output.- Specified by:
renderin interfaceTextRenderer- Parameters:
input- The inputoutput- The output- Throws:
IllegalArgumentException
-
getStyleMap
-
toString
-