DefaultLogger (Apache Ant API)

Package org.apache.tools.ant

## Class DefaultLogger

- java.lang.Object
- - org.apache.tools.ant.DefaultLogger

- All Implemented Interfaces:
    `java.util.EventListener`, `BuildListener`, `BuildLogger`
  Direct Known Subclasses:
    `AnsiColorLogger`, `MailLogger`, `NoBannerLogger`, `ProfileLogger`, `SilentLogger`, `TimestampedLogger`

      public class DefaultLogger
      extends java.lang.Object
      implements BuildLogger

  Writes build events to a PrintStream. Currently, it only writes which targets are being executed, and any messages that get logged.

- - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultLogger()` | Sole constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    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 java.lang.String` | `extractProjectName​(BuildEvent event)` | Get the project name or null
    `protected static java.lang.String` | `formatTime​(long millis)` | Convenience method to format a specified length of time.
    `protected java.lang.String` | `getBuildFailedMessage()` | This is an override point: the message that indicates whether a build failed.
    `protected java.lang.String` | `getBuildSuccessfulMessage()` | This is an override point: the message that indicates that a build succeeded.
    `int` | `getMessageOutputLevel()` |
    `protected java.lang.String` | `getTimestamp()` | Get the current time.
    `protected void` | `log​(java.lang.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.
    `protected void` | `printMessage​(java.lang.String message, java.io.PrintStream stream, int priority)` | Prints a message to a PrintStream.
    `void` | `setEmacsMode​(boolean emacsMode)` | Sets this logger to produce emacs (and other editor) friendly output.
    `void` | `setErrorPrintStream​(java.io.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​(java.io.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 java.lang.Object

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

- - ### Field Detail

    - #### LEFT_COLUMN_SIZE

          public static final int LEFT_COLUMN_SIZE

      Size of left-hand column for right-justified task name.
      See Also:
        `messageLogged(BuildEvent)`, Constant Field Values

    - #### out

          protected java.io.PrintStream out

      PrintStream to write non-error messages to

    - #### err

          protected java.io.PrintStream err

      PrintStream to write error messages to

    - #### msgOutputLevel

          protected int msgOutputLevel

      Lowest level of message to write out

    - #### lSep

          @Deprecated
          protected static final java.lang.String lSep

      Deprecated.
      Line separator

    - #### emacsMode

          protected boolean emacsMode

      Whether or not to use emacs-style output

  - ### Constructor Detail

    - #### DefaultLogger

          public DefaultLogger()

      Sole constructor.

  - ### Method Detail

    - #### setMessageOutputLevel

          public void setMessageOutputLevel​(int level)

      Sets the highest level of message this logger should respond to. Only messages with a message level lower than or equal to the given level should be written to the log.

      Constants for the message levels are in the `Project` class. The order of the levels, from least to most verbose, is `MSG_ERR`, `MSG_WARN`, `MSG_INFO`, `MSG_VERBOSE`, `MSG_DEBUG`.

      The default message level for DefaultLogger is Project.MSG_ERR.

      Specified by:
        `setMessageOutputLevel` in interface `BuildLogger`
      Parameters:
        `level` - the logging level for the logger.

    - #### getMessageOutputLevel

          public int getMessageOutputLevel()

      Specified by:
        `getMessageOutputLevel` in interface `BuildLogger`
      Returns:
        Returns the `currently set` message output level. The `default` implementation of this method returns `MSG_INFO`.

    - #### setOutputPrintStream

          public void setOutputPrintStream​(java.io.PrintStream output)

      Sets the output stream to which this logger is to send its output.
      Specified by:
        `setOutputPrintStream` in interface `BuildLogger`
      Parameters:
        `output` - The output stream for the logger. Must not be `null`.

    - #### setErrorPrintStream

          public void setErrorPrintStream​(java.io.PrintStream err)

      Sets the output stream to which this logger is to send error messages.
      Specified by:
        `setErrorPrintStream` in interface `BuildLogger`
      Parameters:
        `err` - The error stream for the logger. Must not be `null`.

    - #### setEmacsMode

          public void setEmacsMode​(boolean emacsMode)

      Sets this logger to produce emacs (and other editor) friendly output.
      Specified by:
        `setEmacsMode` in interface `BuildLogger`
      Parameters:
        `emacsMode` - `true` if output is to be unadorned so that emacs and other editors can parse files names, etc.

    - #### buildStarted

          public void buildStarted​(BuildEvent event)

      Responds to a build being started by just remembering the current time.
      Specified by:
        `buildStarted` in interface `BuildListener`
      Parameters:
        `event` - Ignored.

    - #### buildFinished

          public void buildFinished​(BuildEvent event)

      Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.
      Specified by:
        `buildFinished` in interface `BuildListener`
      Parameters:
        `event` - An event with any relevant extra information. Must not be `null`.
      See Also:
        `BuildEvent.getException()`

    - #### getBuildFailedMessage

          protected java.lang.String getBuildFailedMessage()

      This is an override point: the message that indicates whether a build failed. Subclasses can change/enhance the message.
      Returns:
        The classic "BUILD FAILED"

    - #### getBuildSuccessfulMessage

          protected java.lang.String getBuildSuccessfulMessage()

      This is an override point: the message that indicates that a build succeeded. Subclasses can change/enhance the message.
      Returns:
        The classic "BUILD SUCCESSFUL"

    - #### targetStarted

          public void targetStarted​(BuildEvent event)

      Logs a message to say that the target has started if this logger allows information-level messages.
      Specified by:
        `targetStarted` in interface `BuildListener`
      Parameters:
        `event` - An event with any relevant extra information. Must not be `null`.
      See Also:
        `BuildEvent.getTarget()`

    - #### targetFinished

          public void targetFinished​(BuildEvent event)

      No-op implementation.
      Specified by:
        `targetFinished` in interface `BuildListener`
      Parameters:
        `event` - Ignored.
      See Also:
        `BuildEvent.getException()`

    - #### taskStarted

          public void taskStarted​(BuildEvent event)

      No-op implementation.
      Specified by:
        `taskStarted` in interface `BuildListener`
      Parameters:
        `event` - Ignored.
      See Also:
        `BuildEvent.getTask()`

    - #### taskFinished

          public void taskFinished​(BuildEvent event)

      No-op implementation.
      Specified by:
        `taskFinished` in interface `BuildListener`
      Parameters:
        `event` - Ignored.
      See Also:
        `BuildEvent.getException()`

    - #### messageLogged

          public void messageLogged​(BuildEvent event)

      Logs a message, if the priority is suitable. In non-emacs mode, task level messages are prefixed by the task name which is right-justified.
      Specified by:
        `messageLogged` in interface `BuildListener`
      Parameters:
        `event` - A BuildEvent containing message information. Must not be `null`.
      See Also:
        `BuildEvent.getMessage()`, `BuildEvent.getException()`, `BuildEvent.getPriority()`

    - #### formatTime

          protected static java.lang.String formatTime​(long millis)

      Convenience method to format a specified length of time.
      Parameters:
        `millis` - Length of time to format, in milliseconds.
      Returns:
        the time as a formatted string.
      See Also:
        `DateUtils.formatElapsedTime(long)`

    - #### printMessage

          protected void printMessage​(java.lang.String message,
                                      java.io.PrintStream stream,
                                      int priority)

      Prints a message to a PrintStream.
      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.)

    - #### log

          protected void log​(java.lang.String message)

      Empty implementation which allows subclasses to receive the same output that is generated here.
      Parameters:
        `message` - Message being logged. Should not be `null`.

    - #### getTimestamp

          protected java.lang.String getTimestamp()

      Get the current time.
      Returns:
        the current time as a formatted string.
      Since:
        Ant1.7.1

    - #### extractProjectName

          protected java.lang.String extractProjectName​(BuildEvent event)

      Get the project name or null
      Parameters:
        `event` - the event
      Returns:
        the project that raised this event
      Since:
        Ant1.7.1