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 JAnsi rendering syntax as the default 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)*)*}%nFor example:
%message{ansi}{WarningStyle=red,bold KeyStyle=white ValueStyle=blue}%nThe call site can look like this:
logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());Note: This class originally copied and then heavily modified code from JAnsi's AnsiRenderer (which is licensed as Apache 2.0.)
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJAnsiTextRenderer
(String[] formats, Map<String, org.fusesource.jansi.AnsiRenderer.Code[]> defaultStyleMap) -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
put
(Map<String, org.fusesource.jansi.AnsiRenderer.Code[]> map, String name, org.fusesource.jansi.AnsiRenderer.Code... codes) void
render
(StringBuilder input, StringBuilder output) Renders input text to an output.private String
Renders the given text with the given names which can be ANSI code names or Log4j style names.void
render
(String input, StringBuilder output, String styleName) Renders input text to an output.private void
render
(org.fusesource.jansi.Ansi ansi, org.fusesource.jansi.AnsiRenderer.Code code) private void
render
(org.fusesource.jansi.Ansi ansi, org.fusesource.jansi.AnsiRenderer.Code... codes) private org.fusesource.jansi.AnsiRenderer.Code
toString()
-
Field Details
-
DefaultExceptionStyleMap
-
DefaultMessageStyleMap
-
PrefedinedStyleMaps
-
beginToken
-
beginTokenLen
private final int beginTokenLen -
endToken
-
endTokenLen
private final int endTokenLen -
styleMap
-
-
Constructor Details
-
JAnsiTextRenderer
-
-
Method Details
-
put
-
getStyleMap
-
render
private void render(org.fusesource.jansi.Ansi ansi, org.fusesource.jansi.AnsiRenderer.Code code) -
render
private void render(org.fusesource.jansi.Ansi ansi, org.fusesource.jansi.AnsiRenderer.Code... codes) -
render
Renders the given text with the given names which can be ANSI code names or Log4j style names.- Parameters:
text
- The text to rendernames
- ANSI code names or Log4j style names.- Returns:
- A rendered string containing ANSI codes.
-
render
public void render(String input, StringBuilder output, String styleName) throws IllegalArgumentException Description copied from interface:TextRenderer
Renders input text to an output.- Specified by:
render
in 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:TextRenderer
Renders input text to an output.- Specified by:
render
in interfaceTextRenderer
- Parameters:
input
- The inputoutput
- The output- Throws:
IllegalArgumentException
-
toCode
-
toString
-