Watch Maven in Color

Color TV!

Color TV!

Maven is not TV, but if I’m going to watch it, I want to see it in color.

Luckily, it’s straightforward, here’s how:

  1. Delete or backup Maven’s lib/slf4j-simple-1.7.5.jar file.
  2. Copy the following files to Maven’s lib folder:
    1. jansi-1.11.jar (if you are on Windows)
    2. The following Log4j 2 jars (where x is a version number):
      1. log4j-api-2.x.jar
      2. log4j-core-2.x.jar
      3. log4j-slf4j-impl-2.x.jar
    3. slf4j-ext-1.7.5.jar
  3. Create a log4j2.xml configuration file in Maven’s conf/logging folder.

<?xml version="1.0" encoding="UTF-8" ?>
    <Property name="maven.logging.root.level">INFO</Property>
    <Console name="console" target="SYSTEM_OUT">
      <PatternLayout pattern="%highlight{[%p] %msg%n%throwable}" />
    <Root level="${sys:maven.logging.root.level}">
      <Appender-ref ref="console"/>

This will give you output that looks like this:


The coloring is enabled in the PatternLayout with the highlight option, which gives you decent default colors for each level. You can produce a fancier layout with:

%highlight{%d [%t] %-5level: %msg%n%throwable}

In the above example. the text between %highlight{ and } is the log event template. For an explanation of the templates option, please see the Log4j manual.

You can override the default colors in the optional {style} option. For example:

%highlight{%d [%t] %-5level: %msg%n%throwable}{FATAL=white, ERROR=red, WARN=blue, INFO=black, DEBUG=green, TRACE=blue}

You can highlight only the a portion of the log event:

%d [%t] %highlight{%-5level: %msg%n%throwable}

You can style one part of the message and highlight the rest the log event:

%style{%d [%t]}{black} %highlight{%-5level: %msg%n%throwable}

Enjoy life in color!

One thought on “Watch Maven in Color

  1. lost_in_logger

    [33m[WARN] The SLF4J binding actually used is not supported by Maven: org.apache.logging.slf4j.Log4jLoggerFactory
    [m[33m[WARN] Maven supported bindings are:
    [m[33m[WARN] (from jar:file:/D:/apache-maven-3.2.5/lib/maven-embedder-3.2.5.jar!/META-INF/maven/



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s