Multicolor Layout for LOG4J
Configure it in your log4j.properties
:
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
Or in XML config:
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender"> <layout class="com.jcabi.log.MulticolorLayout"> <param name="ConversionPattern" value="[%color{%-5p}] %c: %m%n" /> </layout> </appender>
In version 0.9 there is an ability to re-defined standard colors for logging levels. Besides that, it's possible to re-define numeric values of standard colors, for example:
log4j.appender.CONSOLE.layout.Levels=INFO:2;10,WARN:2;32 log4j.appender.CONSOLE.layout.Colors=white:10
Or:
<param name="Levels" value="INFO:2;10" /> <param name="Colors" value="white:10" />
Read JavaDoc of MulticolorLayout
.
The only dependency you need is (you can also download jcabi-log-0.24.3.jar
and add it to the classpath):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-log</artifactId> <version>0.24.3</version> </dependency>