Log4j ANSI Colour Layout

Introduction

This is a ANSI color layout for log4j.

This log4j layout will color messages according to their severity making it easier to pick out critical errors.

Please see the enclosed javadoc.

An example log4j properties file is show below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# $Id: log4j.properties 4124 2012-12-04 20:31:36Z plord $
#
# Copyright 2011 TIBCO Software Inc. All rights reserved.
#
# Simple log4j configuration for test cases
 
log4j.rootLogger=INFO, CONSOLE
 
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=com.tibco.logging.ANSIColorLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-5p [%d{MM-dd-yyyy HH:mm:ss}] %c - %m%n
 
# black
log4j.appender.CONSOLE.layout.all=\u001B[0;30m
 
# red
log4j.appender.CONSOLE.layout.fatal=\u001B[0;31m
 
# light red
log4j.appender.CONSOLE.layout.error=\u001B[1;31m
 
# purple
log4j.appender.CONSOLE.layout.warn=\u001B[0;35m
 
# blue
log4j.appender.CONSOLE.layout.info=\u001B[0;34m
 
# grey
log4j.appender.CONSOLE.layout.debug=\u001B[0;37m
 
# grey
log4j.appender.CONSOLE.layout.stacktrace=\u001B[0;37m
 
# black
log4j.appender.CONSOLE.layout.defaultcolor=\u001B[0;30m