Top Description Fields Constructors Methods
org.apache.tools.ant

public Class DefaultLogger

extends Object
implements BuildLogger
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.BuildLogger, org.apache.tools.ant.BuildListener, java.util.EventListener
Known Direct Subclasses
org.apache.tools.ant.NoBannerLogger, org.apache.tools.ant.listener.AnsiColorLogger, org.apache.tools.ant.listener.MailLogger, org.apache.tools.ant.listener.ProfileLogger, org.apache.tools.ant.listener.SilentLogger, org.apache.tools.ant.listener.TimestampedLogger
Imports
java.io.BufferedReader, .IOException, .PrintStream, .StringReader, java.text.DateFormat, java.util.Date, java.util.stream.Collectors, .Stream, org.apache.tools.ant.util.DateUtils, .StringUtils

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

Field Summary

Modifier and TypeField and Description
protected boolean
emacsMode

Whether or not to use emacs-style output

protected PrintStream
err

PrintStream to write error messages to

public static final int
LEFT_COLUMN_SIZE

Size of left-hand column for right-justified task name.

protected static final String
lSep

Line separator

protected int
msgOutputLevel

Lowest level of message to write out

protected PrintStream
out

PrintStream to write non-error messages to

private long
startTime

Time of the start of the build

Constructor Summary

AccessConstructor and Description
public
DefaultLogger()

Sole constructor.

Method Summary

Modifier and TypeMethod and Description
public void
buildFinished(BuildEvent
An event with any relevant extra information. Must not be null.
event
)

Implements org.apache.tools.ant.BuildListener.buildFinished.

Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.
public void
buildStarted(BuildEvent
Ignored.
event
)

Implements org.apache.tools.ant.BuildListener.buildStarted.

Responds to a build being started by just remembering the current time.
protected String

Returns:

the project that raised this event
extractProjectName
(BuildEvent
the event
event
)

Get the project name or null

protected static String

Returns:

the time as a formatted string.
formatTime
(final long
Length of time to format, in milliseconds.
millis
)

Convenience method to format a specified length of time.

protected String

Returns:

The classic "BUILD FAILED"
getBuildFailedMessage
()

This is an override point: the message that indicates whether a build failed.

protected String

Returns:

The classic "BUILD SUCCESSFUL"
getBuildSuccessfulMessage
()

This is an override point: the message that indicates that a build succeeded.

public int
protected String

Returns:

the current time as a formatted string.
getTimestamp
()

Get the current time.

protected void
log(String
Message being logged. Should not be null.
message
)

Empty implementation which allows subclasses to receive the same output that is generated here.

public void
messageLogged(BuildEvent
A BuildEvent containing message information. Must not be null.
event
)

Implements org.apache.tools.ant.BuildListener.messageLogged.

Logs a message, if the priority is suitable.
protected void
printMessage(final String
The message to print. Should not be null.
message
,
final PrintStream
A PrintStream to print the message to. Must not be null.
stream
,
final int
The priority of the message. (Ignored in this implementation.)
priority
)

Prints a message to a PrintStream.

public void
setEmacsMode(boolean
true if output is to be unadorned so that emacs and other editors can parse files names, etc.
emacsMode
)

Implements org.apache.tools.ant.BuildLogger.setEmacsMode.

Sets this logger to produce emacs (and other editor) friendly output.
public void
setErrorPrintStream(PrintStream
The error stream for the logger. Must not be null.
err
)

Implements org.apache.tools.ant.BuildLogger.setErrorPrintStream.

Sets the output stream to which this logger is to send error messages.
public void
setMessageOutputLevel(int
the logging level for the logger.
level
)

Implements org.apache.tools.ant.BuildLogger.setMessageOutputLevel.

Sets the highest level of message this logger should respond to.
public void
setOutputPrintStream(PrintStream
The output stream for the logger. Must not be null.
output
)

Implements org.apache.tools.ant.BuildLogger.setOutputPrintStream.

Sets the output stream to which this logger is to send its output.
public void
targetFinished(BuildEvent
Ignored.
event
)

Implements org.apache.tools.ant.BuildListener.targetFinished.

No-op implementation.
public void
targetStarted(BuildEvent
An event with any relevant extra information. Must not be null.
event
)

Implements org.apache.tools.ant.BuildListener.targetStarted.

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

Implements org.apache.tools.ant.BuildListener.taskFinished.

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

Implements org.apache.tools.ant.BuildListener.taskStarted.

No-op implementation.
pack-priv static void
throwableMessage(StringBuffer m, Throwable error, boolean verbose)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

emacsModeback to summary
protected boolean emacsMode

Whether or not to use emacs-style output

errback to summary
protected PrintStream err

PrintStream to write error messages to

LEFT_COLUMN_SIZEback to summary
public static final int LEFT_COLUMN_SIZE

Size of left-hand column for right-justified task name.

See Also
messageLogged(BuildEvent)
lSepback to summary
protected static final String lSep

Deprecated

Line separator

Annotations
@Deprecated
msgOutputLevelback to summary
protected int msgOutputLevel

Lowest level of message to write out

outback to summary
protected PrintStream out

PrintStream to write non-error messages to

startTimeback to summary
private long startTime

Time of the start of the build

Constructor Detail

DefaultLoggerback to summary
public DefaultLogger()

Sole constructor.

Method Detail

buildFinishedback to summary
public void buildFinished(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.buildFinished.

Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.

Parameters
event:BuildEvent

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

buildStartedback to summary
public void buildStarted(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.buildStarted.

Responds to a build being started by just remembering the current time.

Parameters
event:BuildEvent

Ignored.

extractProjectNameback to summary
protected String extractProjectName(BuildEvent event)

Get the project name or null

Parameters
event:BuildEvent

the event

Returns:String

the project that raised this event

Since
Ant1.7.1
formatTimeback to summary
protected static String formatTime(final long millis)

Convenience method to format a specified length of time.

Parameters
millis:long

Length of time to format, in milliseconds.

Returns:String

the time as a formatted string.

See Also
DateUtils#formatElapsedTime(long)
getBuildFailedMessageback to summary
protected String getBuildFailedMessage()

This is an override point: the message that indicates whether a build failed. Subclasses can change/enhance the message.

Returns:String

The classic "BUILD FAILED"

getBuildSuccessfulMessageback to summary
protected String getBuildSuccessfulMessage()

This is an override point: the message that indicates that a build succeeded. Subclasses can change/enhance the message.

Returns:String

The classic "BUILD SUCCESSFUL"

getMessageOutputLevelback to summary
public int getMessageOutputLevel()

Overrides default org.apache.tools.ant.BuildLogger.getMessageOutputLevel.

Returns:int

Doc from org.apache.tools.ant.BuildLogger.getMessageOutputLevel.

Returns the currently set message output level. The default implementation of this method returns MSG_INFO.

Annotations
@Override
getTimestampback to summary
protected String getTimestamp()

Get the current time.

Returns:String

the current time as a formatted string.

Since
Ant1.7.1
logback to summary
protected void log(String message)

Empty implementation which allows subclasses to receive the same output that is generated here.

Parameters
message:String

Message being logged. Should not be null.

messageLoggedback to summary
public void messageLogged(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.messageLogged.

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:BuildEvent

A BuildEvent containing message information. Must not be null.

printMessageback to summary
protected void printMessage(final String message, final PrintStream stream, final int priority)

Prints a message to a PrintStream.

Parameters
message:String

The message to print. Should not be null.

stream:PrintStream

A PrintStream to print the message to. Must not be null.

priority:int

The priority of the message. (Ignored in this implementation.)

setEmacsModeback to summary
public void setEmacsMode(boolean emacsMode)

Implements org.apache.tools.ant.BuildLogger.setEmacsMode.

Sets this logger to produce emacs (and other editor) friendly output.

Parameters
emacsMode:boolean

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

setErrorPrintStreamback to summary
public void setErrorPrintStream(PrintStream err)

Implements org.apache.tools.ant.BuildLogger.setErrorPrintStream.

Sets the output stream to which this logger is to send error messages.

Parameters
err:PrintStream

The error stream for the logger. Must not be null.

setMessageOutputLevelback to summary
public void setMessageOutputLevel(int level)

Implements org.apache.tools.ant.BuildLogger.setMessageOutputLevel.

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.

Parameters
level:int

the logging level for the logger.

setOutputPrintStreamback to summary
public void setOutputPrintStream(PrintStream output)

Implements org.apache.tools.ant.BuildLogger.setOutputPrintStream.

Sets the output stream to which this logger is to send its output.

Parameters
output:PrintStream

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

targetFinishedback to summary
public void targetFinished(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.targetFinished.

No-op implementation.

Parameters
event:BuildEvent

Ignored.

targetStartedback to summary
public void targetStarted(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.targetStarted.

Logs a message to say that the target has started if this logger allows information-level messages.

Parameters
event:BuildEvent

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

taskFinishedback to summary
public void taskFinished(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.taskFinished.

No-op implementation.

Parameters
event:BuildEvent

Ignored.

taskStartedback to summary
public void taskStarted(BuildEvent event)

Implements org.apache.tools.ant.BuildListener.taskStarted.

No-op implementation.

Parameters
event:BuildEvent

Ignored.

throwableMessageback to summary
pack-priv static void throwableMessage(StringBuffer m, Throwable error, boolean verbose)