AnsiColorLogger (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.listener, class: AnsiColorLogger

# Class AnsiColorLogger

java.lang.Object
org.apache.tools.ant.DefaultLogger
org.apache.tools.ant.listener.AnsiColorLogger

All Implemented Interfaces:
  `EventListener, BuildListener, BuildLogger`

public class AnsiColorLogger extends DefaultLogger
Uses ANSI Color Code Sequences to colorize messages sent to the console.

If used with the -logfile option, the output file will contain all the necessary escape codes to display the text in colorized mode when displayed in the console using applications like cat, more, etc.

This is designed to work on terminals that support ANSI color codes. It works on XTerm, ETerm, Mindterm, etc. It also works on Win9x (with ANSI.SYS loaded.)

NOTE: It doesn't work on WinNT's COMMAND.COM even with ANSI.SYS loaded.

The default colors used for differentiating the message levels can be changed by editing the /org/apache/tools/ant/listener/defaults.properties file. This file contains 5 key/value pairs:

    AnsiColorLogger.ERROR_COLOR=2;31
    AnsiColorLogger.WARNING_COLOR=2;35
    AnsiColorLogger.INFO_COLOR=2;36
    AnsiColorLogger.VERBOSE_COLOR=2;32
    AnsiColorLogger.DEBUG_COLOR=2;34

Another option is to pass a system variable named ant.logger.defaults, with value set to the path of the file that contains user defined Ansi Color Codes, to the java command using -D option.

To change these colors use the following chart:

## ANSI COLOR LOGGER CONFIGURATION

Format for AnsiColorLogger.*= Attribute;Foreground;Background Attribute is one of the following:

     0 -> Reset All Attributes (return to normal mode)
     1 -> Bright (Usually turns on BOLD)
     2 -> Dim
     3 -> Underline
     5 -> link
     7 -> Reverse
     8 -> Hidden

Foreground is one of the following:

     30 -> Black
     31 -> Red
     32 -> Green
     33 -> Yellow
     34 -> Blue
     35 -> Magenta
     36 -> Cyan
     37 -> White

Background is one of the following:

     40 -> Black
     41 -> Red
     42 -> Green
     43 -> Yellow
     44 -> Blue
     45 -> Magenta
     46 -> Cyan
     47 -> White

- ## Field Summary

  ### Fields inherited from class DefaultLogger

  `emacsMode, err, LEFT_COLUMN_SIZE, lSep, msgOutputLevel, out`
  Modifier and Type
  Field
  Description
  `protected boolean`
  `emacsMode`
  Whether or not to use emacs-style output
  `protected PrintStream`
  `err`
  PrintStream to write error messages to
  `static final int`
  `LEFT_COLUMN_SIZE`
  Size of left-hand column for right-justified task name.
  `protected static final String`
  `lSep`
  Deprecated.
  `protected int`
  `msgOutputLevel`
  Lowest level of message to write out
  `protected PrintStream`
  `out`
  PrintStream to write non-error messages to

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AnsiColorLogger()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `printMessage(String message, PrintStream stream, int priority)`
  Prints a message to a PrintStream.

  ### Methods inherited from class DefaultLogger

  `buildFinished, buildStarted, extractProjectName, formatTime, getBuildFailedMessage, getBuildSuccessfulMessage, getMessageOutputLevel, getTimestamp, log, messageLogged, setEmacsMode, setErrorPrintStream, setMessageOutputLevel, setOutputPrintStream, targetFinished, targetStarted, taskFinished, taskStarted`
  Modifier and Type
  Method
  Description
  `void`
  `buildFinished(BuildEvent event)`
  Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.
  `void`
  `buildStarted(BuildEvent event)`
  Responds to a build being started by just remembering the current time.
  `protected String`
  `extractProjectName(BuildEvent event)`
  Get the project name or null
  `protected static String`
  `formatTime(long millis)`
  Convenience method to format a specified length of time.
  `protected String`
  `getBuildFailedMessage()`
  This is an override point: the message that indicates whether a build failed.
  `protected String`
  `getBuildSuccessfulMessage()`
  This is an override point: the message that indicates that a build succeeded.
  `int`
  `getMessageOutputLevel()`
  `protected String`
  `getTimestamp()`
  Get the current time.
  `protected void`
  `log(String message)`
  Empty implementation which allows subclasses to receive the same output that is generated here.
  `void`
  `messageLogged(BuildEvent event)`
  Logs a message, if the priority is suitable.
  `void`
  `setEmacsMode(boolean emacsMode)`
  Sets this logger to produce emacs (and other editor) friendly output.
  `void`
  `setErrorPrintStream(PrintStream err)`
  Sets the output stream to which this logger is to send error messages.
  `void`
  `setMessageOutputLevel(int level)`
  Sets the highest level of message this logger should respond to.
  `void`
  `setOutputPrintStream(PrintStream output)`
  Sets the output stream to which this logger is to send its output.
  `void`
  `targetFinished(BuildEvent event)`
  No-op implementation.
  `void`
  `targetStarted(BuildEvent event)`
  Logs a message to say that the target has started if this logger allows information-level messages.
  `void`
  `taskFinished(BuildEvent event)`
  No-op implementation.
  `void`
  `taskStarted(BuildEvent event)`
  No-op implementation.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AnsiColorLogger

    public AnsiColorLogger()

- ## Method Details

  - ### printMessage

    protected void printMessage(String message, PrintStream stream, int priority)
    Description copied from class: `DefaultLogger`
    Prints a message to a PrintStream.
    Overrides:
      `printMessage` in class `DefaultLogger`
    Parameters:
      `message` - The message to print. Should not be `null`.
      `stream` - A PrintStream to print the message to. Must not be `null`.
      `priority` - The priority of the message. (Ignored in this implementation.)
    See Also:
      - .