0

How can I enable the AnsiColorLogger Apache Ant built-in logger by default without running manually command ant -logger org.apache.tools.ant.listener.AnsiColorLogger or adding the environment variable ANT_ARGS ?


I tried to run the command from the ant build.
build.xml

<exec dir="${sdk.dir}" executable="cmd">
    <arg value="${sdk.dir}" />
    <arg value="AnsiColorLogger.cmd" />
</exec>

AnsiColorLogger.cmd

START -logger org.apache.tools.ant.listener.AnsiColorLogger

Then I run the ant command to compile my project but the logs are not colored.

Fuiba@FUIBA D:\DEV\TEST\proj
> ant
Buildfile: D:\DEV\TEST\proj\build.xml
Trying to override old definition of task for
     [exec] Microsoft Windows [Versione 10.0.10240]
     [exec] (c) 2015 Microsoft Corporation. Tutti i diritti sono riservati.
     [exec]
     [exec] Fuiba@FUIBA D:\DEV\TEST\proj
     [exec] >

Instead when I run ant -logger org.apache.tools.ant.listener.AnsiColorLogger it works.

Mustapha Aoussar
  • 5,833
  • 15
  • 62
  • 107
  • 1
    Possible duplicate of [Is it possible to specify logger for ant inside build.xml?](http://stackoverflow.com/questions/5721513/is-it-possible-to-specify-logger-for-ant-inside-build-xml) – Chad Nouis Feb 22 '16 at 15:41
  • @ChadNouis Thank you! but that does not solve my problem. – Mustapha Aoussar Feb 23 '16 at 10:09

1 Answers1

0

When you say you run ant directly it works, how are you running it? From ant's own documentation it doesn't support Windows NT derivatives (including Windows 8 , 10, etc). From your output, it looks like you're running on Windows, so please go into more detail on how to reproduce this problem.

From ant's manual:

Note: It doesn't work on WinNT and successors, even when a COMMAND.COM console loaded with ANSI.SYS is used.

Source: https://ant.apache.org/manual/index.html

If you are running ant from within a terminal that supports ANSI escape sequences, like Cygwin's MinTTY or CMDER, you try passing the env argument to your exec task:

<exec dir="${sdk.dir}" executable="cmd">
    <env key="ANT_ARGS" value="-logger org.apache.tools.ant.listener.AnsiColorLogger"/>
    <arg value="${sdk.dir}" />
    <arg value="AnsiColorLogger.cmd" />
</exec>
Dharman
  • 30,962
  • 25
  • 85
  • 135