org.apache.tools.ant

Class DefaultLogger

public class DefaultLogger extends 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
protected booleanemacsMode
Whether or not to use emacs-style output
protected PrintStreamerr
PrintStream to write error messages to
protected static StringlSep
Line separator
static intLEFT_COLUMN_SIZE
Size of left-hand column for right-justified task name.
protected intmsgOutputLevel
Lowest level of message to write out
protected PrintStreamout
PrintStream to write non-error messages to
Constructor Summary
DefaultLogger()
Sole constructor.
Method Summary
voidbuildFinished(BuildEvent event)
Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.
voidbuildStarted(BuildEvent event)
Responds to a build being started by just remembering the current time.
protected static StringformatTime(long millis)
Convenience method to format a specified length of time.
protected voidlog(String message)
Empty implementation which allows subclasses to receive the same output that is generated here.
voidmessageLogged(BuildEvent event)
Logs a message, if the priority is suitable.
protected voidprintMessage(String message, PrintStream stream, int priority)
Prints a message to a PrintStream.
voidsetEmacsMode(boolean emacsMode)
Sets this logger to produce emacs (and other editor) friendly output.
voidsetErrorPrintStream(PrintStream err)
Sets the output stream to which this logger is to send error messages.
voidsetMessageOutputLevel(int level)
Sets the highest level of message this logger should respond to.
voidsetOutputPrintStream(PrintStream output)
Sets the output stream to which this logger is to send its output.
voidtargetFinished(BuildEvent event)
No-op implementation.
voidtargetStarted(BuildEvent event)
Logs a message to say that the target has started if this logger allows information-level messages.
voidtaskFinished(BuildEvent event)
No-op implementation.
voidtaskStarted(BuildEvent event)
No-op implementation.

Field Detail

emacsMode

protected boolean emacsMode
Whether or not to use emacs-style output

err

protected PrintStream err
PrintStream to write error messages to

lSep

protected static final String lSep
Line separator

LEFT_COLUMN_SIZE

public static final int LEFT_COLUMN_SIZE
Size of left-hand column for right-justified task name.

See Also: messageLogged

msgOutputLevel

protected int msgOutputLevel
Lowest level of message to write out

out

protected PrintStream out
PrintStream to write non-error messages to

Constructor Detail

DefaultLogger

public DefaultLogger()
Sole constructor.

Method Detail

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.

Parameters: event An event with any relevant extra information. Must not be null.

buildStarted

public void buildStarted(BuildEvent event)
Responds to a build being started by just remembering the current time.

Parameters: event Ignored.

formatTime

protected static 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

log

protected void log(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.

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.

Parameters: event A BuildEvent containing message information. Must not be null.

printMessage

protected void printMessage(String message, 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.)

setEmacsMode

public void setEmacsMode(boolean emacsMode)
Sets this logger to produce emacs (and other editor) friendly output.

Parameters: emacsMode true if output is to be unadorned so that emacs and other editors can parse files names, etc.

setErrorPrintStream

public void setErrorPrintStream(PrintStream err)
Sets the output stream to which this logger is to send error messages.

Parameters: err The error stream for the logger. Must not be null.

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 {@link Project 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.

Parameters: level the logging level for the logger.

setOutputPrintStream

public void setOutputPrintStream(PrintStream output)
Sets the output stream to which this logger is to send its output.

Parameters: output The output stream for the logger. Must not be null.

targetFinished

public void targetFinished(BuildEvent event)
No-op implementation.

Parameters: event Ignored.

targetStarted

public void targetStarted(BuildEvent event)
Logs a message to say that the target has started if this logger allows information-level messages.

Parameters: event An event with any relevant extra information. Must not be null.

taskFinished

public void taskFinished(BuildEvent event)
No-op implementation.

Parameters: event Ignored.

taskStarted

public void taskStarted(BuildEvent event)
No-op implementation.

Parameters: event Ignored.

Copyright