Maven 2 & 3
  1. Maven 2 & 3
  2. MNG-3507

ANSI Color logging for improved output visibility.

    Details

    • Complexity:
      Intermediate
    • Number of attachments :
      3

      Description

      Is it possible for Maven to use ANSI color logging? IMO it would make Maven logs much easier to read and increase the visibility of items that the user want to see at any given point in time.

      I think Andrew Williams did some work under Plexus sandbox to enable color logging. There also a color logger available in Ant.
      http://ant.apache.org/manual/listeners.html#AnsiColorLogger

        Issue Links

          Activity

          Hide
          David Bernhard added a comment -

          Yes. It's possible - I've made a maven project that does it. The only catch is that under windows, while it works perfectly in cygwin xterms the native CMD.exe does not support it. I'll attach a zip in a minute.

          Show
          David Bernhard added a comment - Yes. It's possible - I've made a maven project that does it. The only catch is that under windows, while it works perfectly in cygwin xterms the native CMD.exe does not support it. I'll attach a zip in a minute.
          Hide
          David Bernhard added a comment -

          To install, make the project and put the jar in $M2_HOME/lib.

          Then, patch the plexus file in the maven uberjar:

          In lib/, execute
          jar xf maven-2.0.9-uber.jar org/codehaus/plexus/plexus-bootstrap.xml

          In the unzipped file, edit the entry
          org.codehaus.plexus.logging.console.ConsoleLoggerManager
          to
          ch.elca.el4j.maven.logging.FormattedLoggerManager

          add it to the uberjar with (again in lib/)
          jar uf maven-2.0.9-uber.jar org/codehaus/plexus/plexus-bootstrap.xml

          and delete the org/ directory.

          Ansi color is output only when you call maven with the option -Dplexus.logger.type=ansi.

          Show
          David Bernhard added a comment - To install, make the project and put the jar in $M2_HOME/lib . Then, patch the plexus file in the maven uberjar: In lib/ , execute jar xf maven-2.0.9-uber.jar org/codehaus/plexus/plexus-bootstrap.xml In the unzipped file, edit the entry org.codehaus.plexus.logging.console.ConsoleLoggerManager to ch.elca.el4j.maven.logging.FormattedLoggerManager add it to the uberjar with (again in lib/) jar uf maven-2.0.9-uber.jar org/codehaus/plexus/plexus-bootstrap.xml and delete the org/ directory. Ansi color is output only when you call maven with the option -Dplexus.logger.type=ansi .
          Hide
          Vincent Siveton added a comment -

          el4j is under LGPL not ASL

          Show
          Vincent Siveton added a comment - el4j is under LGPL not ASL
          Hide
          David Bernhard added a comment -

          It's no problem for us to release our maven utilities (colourlogger etc.) under the ASL or a similar license too. The LGPL is meant for the main framework - we'd be happy to contribute some of our utilities we use to help building el4j with maven to the maven community and adapt the license accordingly.

          Show
          David Bernhard added a comment - It's no problem for us to release our maven utilities (colourlogger etc.) under the ASL or a similar license too. The LGPL is meant for the main framework - we'd be happy to contribute some of our utilities we use to help building el4j with maven to the maven community and adapt the license accordingly.
          Hide
          Sean Flanigan added a comment -

          The maven-colorlogger project references a chain of el4j parent poms which aren't in the zip. If anyone else wants to try it, I found the immediate parent here: https://el4j.svn.sourceforge.net/svnroot/el4j/trunk/el4j/maven/pom.xml
          In the end, I just removed the parent reference, told the maven-compiler-plugin to compile for 1.5, and it all worked.

          An even easier way to try it is to download the el4j binaries from https://sourceforge.net/project/showfiles.php?group_id=147215&package_id=162180&release_id=638658 and use the modified Maven 2.0.9 therein.

          BTW, if anyone was using an awk hack like this one while waiting for colour logging in Maven - http://blog.bazoud.com/post/2008/10/20/Maven-in-colour-/-Maven-en-couleur - watch out for interactive goals which mess up awk's line buffering...

          Show
          Sean Flanigan added a comment - The maven-colorlogger project references a chain of el4j parent poms which aren't in the zip. If anyone else wants to try it, I found the immediate parent here: https://el4j.svn.sourceforge.net/svnroot/el4j/trunk/el4j/maven/pom.xml In the end, I just removed the parent reference, told the maven-compiler-plugin to compile for 1.5, and it all worked. An even easier way to try it is to download the el4j binaries from https://sourceforge.net/project/showfiles.php?group_id=147215&package_id=162180&release_id=638658 and use the modified Maven 2.0.9 therein. BTW, if anyone was using an awk hack like this one while waiting for colour logging in Maven - http://blog.bazoud.com/post/2008/10/20/Maven-in-colour-/-Maven-en-couleur - watch out for interactive goals which mess up awk's line buffering...
          Hide
          Sean Flanigan added a comment -

          pom.xml for maven-colorlogger, modified to remove parent reference.

          Show
          Sean Flanigan added a comment - pom.xml for maven-colorlogger, modified to remove parent reference.
          Hide
          Johannes Buchner added a comment - - edited

          A slightly different approach, yet considerably easier.
          http://johannes.jakeapp.com/blog/?p=28
          Works of course on environments that support it, but assuming all unices want it, you can just fix your "Maven2 Start Up Batch" script to add this.

          Like so: (at the end of the mvn bash script distributed)

          exec "$JAVACMD" \
          $MAVEN_OPTS \
          -classpath "$

          {M2_HOME}"/boot/classworlds-*.jar \
          "-Dclassworlds.conf=${M2_HOME}

          /bin/m2.conf" \
          "-Dmaven.home=$

          {M2_HOME}

          " \
          $

          {CLASSWORLDS_LAUNCHER}

          $QUOTED_ARGS |
          sed -e 's/Tests run: ([^,]), Failures: ([^,]), Errors: ([^,]), Skipped: ([^,])/[1;32mTests run: \1[0m, Failures: [1;31m\2[0m, Errors: [1;33m\3[0m, Skipped: [1;34m\4[0m/g' \
          -e 's/([WARN].*)/[1;33m\1[0m/g' \
          -e 's/([INFO].*)/[1;34m\1[0m/g' \
          -e 's/([ERROR].*)/[1;31m\1[0m/g'

          Or is that just the one gentoo provides? Anyhow, you could provide this to your distributers.

          Show
          Johannes Buchner added a comment - - edited A slightly different approach, yet considerably easier. http://johannes.jakeapp.com/blog/?p=28 Works of course on environments that support it, but assuming all unices want it, you can just fix your "Maven2 Start Up Batch" script to add this. Like so: (at the end of the mvn bash script distributed) exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "$ {M2_HOME}"/boot/classworlds-*.jar \ "-Dclassworlds.conf=${M2_HOME} /bin/m2.conf" \ "-Dmaven.home=$ {M2_HOME} " \ $ {CLASSWORLDS_LAUNCHER} $QUOTED_ARGS | sed -e 's/Tests run: ( [^,] ), Failures: ( [^,] ), Errors: ( [^,] ), Skipped: ( [^,] )/[1;32mTests run: \1[0m, Failures: [1;31m\2[0m, Errors: [1;33m\3[0m, Skipped: [1;34m\4[0m/g' \ -e 's/([WARN].*)/[1;33m\1[0m/g' \ -e 's/([INFO].*)/[1;34m\1[0m/g' \ -e 's/([ERROR].*)/[1;31m\1[0m/g' Or is that just the one gentoo provides? Anyhow, you could provide this to your distributers.
          Hide
          David Leonard added a comment -

          A comment on Johannes Buchner's sed approach: I discovered this fails with archetype:generate because the prompts are hidden by sed's line buffering

          Show
          David Leonard added a comment - A comment on Johannes Buchner's sed approach: I discovered this fails with archetype:generate because the prompts are hidden by sed's line buffering
          Hide
          Emmanuel Hugonnet added a comment -

          I have implemented it on the scmchanglog-maven-plugin on Codehaus (not on the release version) as a PoC without any dependency (alas not on Windows I am afraid). This is just a wrapper on the current Maven Logger, so it should be easy to add to the current Maven distribution.
          http://svn.codehaus.org/mojo/trunk/mojo/scmchangelog-maven-plugin/src/main/java/org/codehaus/mojo/scmchangelog/scm/util/ColorConsoleLogger.java

          Emmanuel

          Show
          Emmanuel Hugonnet added a comment - I have implemented it on the scmchanglog-maven-plugin on Codehaus (not on the release version) as a PoC without any dependency (alas not on Windows I am afraid). This is just a wrapper on the current Maven Logger, so it should be easy to add to the current Maven distribution. http://svn.codehaus.org/mojo/trunk/mojo/scmchangelog-maven-plugin/src/main/java/org/codehaus/mojo/scmchangelog/scm/util/ColorConsoleLogger.java Emmanuel
          Hide
          Emmanuel Hugonnet added a comment - - edited

          A patch for Plexus used to build Maven 2.2.0 (unix only)

          I have built a Maven 2.2.0 version with colorized traces.
          You can download it there: http://www.ehsavoie.com/2009/07/maven-en-couleurs.html
          You have to run the command with -Dcolorized.console=true

          For example:
          mvn -Dcolorized.console=true clean install

          Show
          Emmanuel Hugonnet added a comment - - edited A patch for Plexus used to build Maven 2.2.0 (unix only) I have built a Maven 2.2.0 version with colorized traces. You can download it there: http://www.ehsavoie.com/2009/07/maven-en-couleurs.html You have to run the command with -Dcolorized.console=true For example: mvn -Dcolorized.console=true clean install
          Hide
          Don Brown added a comment -

          If you don't want to wait till this issue gets fixed, I wrote a little tool called "Console Colorizer" to have complete control over colorizing the Maven 2 output that works with any version of Maven.

          Show
          Don Brown added a comment - If you don't want to wait till this issue gets fixed, I wrote a little tool called "Console Colorizer" to have complete control over colorizing the Maven 2 output that works with any version of Maven.
          Hide
          Gary Gregory added a comment -

          Note that if Maven used JAnsi, color logging would work everywhere including Windows.

          Show
          Gary Gregory added a comment - Note that if Maven used JAnsi, color logging would work everywhere including Windows.
          Hide
          Michael Osipov added a comment -

          Is this ticket still necessary? With the new logging backend you can put in logback and colorize everything yourserf.

          Show
          Michael Osipov added a comment - Is this ticket still necessary? With the new logging backend you can put in logback and colorize everything yourserf.
          Hide
          Gary Gregory added a comment -

          IMO, Maven should colorize on the console by default.

          Show
          Gary Gregory added a comment - IMO, Maven should colorize on the console by default.
          Hide
          Michael Osipov added a comment -

          Gary Gregory, the question is, of course, how should this look like? Everyone has different expectations. While I do like this solution, others don't. Moreover, that would mean swap SLF4J Simple for something more heavyweight like Logback with Jansi. Is that intended by default? Logback libs add another 700 kB, and Jansi 115 kB. Quite a lot. Maybe a patched SLF4J Simple would suffice.

          Show
          Michael Osipov added a comment - Gary Gregory , the question is, of course, how should this look like? Everyone has different expectations. While I do like this solution, others don't. Moreover, that would mean swap SLF4J Simple for something more heavyweight like Logback with Jansi. Is that intended by default? Logback libs add another 700 kB, and Jansi 115 kB. Quite a lot. Maybe a patched SLF4J Simple would suffice.
          Hide
          Gary Gregory added a comment -

          700k? 100k? Who cares when running maven for even a simple project downloads tons of plugins and dependencies! My local repo is GBs. We are not running builds on a light bulb pick a sensible set of default colors.

          Show
          Gary Gregory added a comment - 700k? 100k? Who cares when running maven for even a simple project downloads tons of plugins and dependencies! My local repo is GBs. We are not running builds on a light bulb pick a sensible set of default colors.

            People

            • Assignee:
              Unassigned
              Reporter:
              Rahul Thakur
            • Votes:
              30 Vote for this issue
              Watchers:
              26 Start watching this issue

              Dates

              • Created:
                Updated: