Class MulticolorLayout
- java.lang.Object
-
- org.apache.log4j.Layout
-
- org.apache.log4j.EnhancedPatternLayout
-
- com.jcabi.log.MulticolorLayout
-
- All Implemented Interfaces:
org.apache.log4j.spi.OptionHandler
public final class MulticolorLayout extends org.apache.log4j.EnhancedPatternLayout
Multi-color layout for LOG4J.Use it in your LOG4J configuration:
log4j.rootLogger=INFO, CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%-5p}] %c: %m%n
The part of the message wrapped with
%color{...}
will change its color according to the logging level of the event. Without this highlighting the behavior of the layout is identical toEnhancedPatternLayout
. You can use%color-red{...}
if you want to use specifically red color for the wrapped piece of text. Supported colors are:red
,blue
,yellow
,cyan
,black
, andwhite
.Besides that you can specify any ANSI color you like with
%color-<attr>;<bg>;<fg>{...}
, where<attr>
is a binary mask of attributes,<bg>
is a background color, and<fg>
is a foreground color. Read more about ANSI escape code.This class or its parents are not serializable.
Maven dependency for this class is (see How to use with Maven instructions):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-log</artifactId> </dependency>
- Since:
- 0.1.10
- See Also:
- ANSI escape code, PatternLayout from LOG4J, How to use with Maven
-
-
Constructor Summary
Constructors Constructor Description MulticolorLayout()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(org.apache.log4j.spi.LoggingEvent event)
void
setColors(String cols)
Allow to overwrite or specify new ANSI color names in a javascript map like format.void
setConversionPattern(String pattern)
void
setLevels(String lev)
Allow to overwrite the ANSI color values for the log levels in a javascript map like format.
-
-
-
Method Detail
-
setConversionPattern
public void setConversionPattern(String pattern)
- Overrides:
setConversionPattern
in classorg.apache.log4j.EnhancedPatternLayout
-
setColors
public void setColors(String cols)
Allow to overwrite or specify new ANSI color names in a javascript map like format.- Parameters:
cols
- JavaScript like map of color names- Since:
- 0.9
-
setLevels
public void setLevels(String lev)
Allow to overwrite the ANSI color values for the log levels in a javascript map like format.- Parameters:
lev
- JavaScript like map of levels- Since:
- 0.9
-
format
public String format(org.apache.log4j.spi.LoggingEvent event)
- Overrides:
format
in classorg.apache.log4j.EnhancedPatternLayout
-
-