Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Color console logging for log4j and jdk
Branch: master


Color console logging for log4j and jdk


  • Download the latest color-loggers jar from releases or build them yourself
  • Download jansi-1.11.jar - optional, see below
    (jansi-1.11 is the latest one at this time, but I use nothing fancy, so I don't expect surprises with other versions)
  • Make sure the jar(s) mentioned above are somewhere in the classpath (whatever method you are using for your project)

On Mac OS X, Linux, UNIX, or Windows with ansicon you can use AnsiColorConsole flavors of the loggers, but if you want Windows without ansicon, then you should use JAnsiColorConsole and you also need jansi.

There are pros and cons for each option, I hope to write an article when I have some time.


  • In the java logging configuration file (default in JAVA_HOME/lib/ use
  • com.colorlog.jdk.AnsiColorConsoleHandler or com.colorlog.jdk.JAnsiColorConsoleHandler as handler.
    They work the same as java.util.logging.ConsoleHandler.
    See an example in src/test/resources/

That's all


  • In (or whatever config file you use for log4j) use com.colorlog.log4j.AnsiColorConsoleAppender or com.colorlog.log4j.JAnsiColorConsoleAppender as appender.
    They work the same as org.apache.log4j.ConsoleAppender.
    See an example in src/test/resources/ or src/test/resources/log4j.xml


  • Logback already allows for colored output using jansi, but does not allow configuring the colors. But now you can. In logback.xml (or whatever config file you use for Logback) find the appender that uses ch.qos.logback.core.ConsoleAppender, find the encoder element, and add a class attribute with the value of com.colorlog.logback.ColorPatternLayoutEncoder.
    And as children of the encoder element you can add the following elements to configure the colors:
    • <errorColor>1;31</errorColor>
    • <warningColor>1;33</warningColor>
    • <infoColor>32</infoColor>
    • <debugColor>36</debugColor>
    • <traceColor>1;30</traceColor>

The values should be valid ANSI escape sequences, without the {esc}[ and the without the final 'm' See an example in src/test/resources/logback.xml

That's all !


Nothing special about it, you configure the logger "underneath it" (jdk or log4j or logback).


  • mvn clean install

But maven (or maybe junit?) highjacks the output of the test. So not all the lines that would normally be colored are colored in the maven test. The best way to try things is to run the tests in as a normal application against the final jar (with the 3rd party jars in "the right place").

Something went wrong with that request. Please try again.