Package org.apache.tools.ant
Class DefaultLogger
java.lang.Object
org.apache.tools.ant.DefaultLogger
- All Implemented Interfaces:
EventListener
,BuildListener
,BuildLogger
- Direct Known Subclasses:
AnsiColorLogger
,MailLogger
,NoBannerLogger
,ProfileLogger
,SilentLogger
,TimestampedLogger
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 TypeFieldDescriptionprotected boolean
Whether or not to use emacs-style outputprotected PrintStream
PrintStream to write error messages tostatic final int
Size of left-hand column for right-justified task name.protected static final String
Deprecated.protected int
Lowest level of message to write outprotected PrintStream
PrintStream to write non-error messages to -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 nullprotected static String
formatTime
(long millis) Convenience method to format a specified length of time.protected String
This is an override point: the message that indicates whether a build failed.protected String
This is an override point: the message that indicates that a build succeeded.int
protected String
Get the current time.protected void
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
(String message, 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
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.
-
Field Details
-
LEFT_COLUMN_SIZE
public static final int LEFT_COLUMN_SIZESize of left-hand column for right-justified task name.- See Also:
-
out
PrintStream to write non-error messages to -
err
PrintStream to write error messages to -
msgOutputLevel
protected int msgOutputLevelLowest level of message to write out -
lSep
-
emacsMode
protected boolean emacsModeWhether or not to use emacs-style output
-
-
Constructor Details
-
DefaultLogger
public DefaultLogger()Sole constructor.
-
-
Method Details
-
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, isMSG_ERR
,MSG_WARN
,MSG_INFO
,MSG_VERBOSE
,MSG_DEBUG
.The default message level for DefaultLogger is Project.MSG_ERR.
- Specified by:
setMessageOutputLevel
in interfaceBuildLogger
- Parameters:
level
- the logging level for the logger.
-
getMessageOutputLevel
public int getMessageOutputLevel()- Specified by:
getMessageOutputLevel
in interfaceBuildLogger
- Returns:
- Returns the
currently set
message output level. Thedefault
implementation of this method returnsMSG_INFO
.
-
setOutputPrintStream
Sets the output stream to which this logger is to send its output.- Specified by:
setOutputPrintStream
in interfaceBuildLogger
- Parameters:
output
- The output stream for the logger. Must not benull
.
-
setErrorPrintStream
Sets the output stream to which this logger is to send error messages.- Specified by:
setErrorPrintStream
in interfaceBuildLogger
- Parameters:
err
- The error stream for the logger. Must not benull
.
-
setEmacsMode
public void setEmacsMode(boolean emacsMode) Sets this logger to produce emacs (and other editor) friendly output.- Specified by:
setEmacsMode
in interfaceBuildLogger
- Parameters:
emacsMode
-true
if output is to be unadorned so that emacs and other editors can parse files names, etc.
-
buildStarted
Responds to a build being started by just remembering the current time.- Specified by:
buildStarted
in interfaceBuildListener
- Parameters:
event
- Ignored.
-
buildFinished
Prints whether the build succeeded or failed, any errors the occurred during the build, and how long the build took.- Specified by:
buildFinished
in interfaceBuildListener
- Parameters:
event
- An event with any relevant extra information. Must not benull
.- See Also:
-
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
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
Logs a message to say that the target has started if this logger allows information-level messages.- Specified by:
targetStarted
in interfaceBuildListener
- Parameters:
event
- An event with any relevant extra information. Must not benull
.- See Also:
-
targetFinished
No-op implementation.- Specified by:
targetFinished
in interfaceBuildListener
- Parameters:
event
- Ignored.- See Also:
-
taskStarted
No-op implementation.- Specified by:
taskStarted
in interfaceBuildListener
- Parameters:
event
- Ignored.- See Also:
-
taskFinished
No-op implementation.- Specified by:
taskFinished
in interfaceBuildListener
- Parameters:
event
- Ignored.- See Also:
-
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.- Specified by:
messageLogged
in interfaceBuildListener
- Parameters:
event
- A BuildEvent containing message information. Must not benull
.- See Also:
-
formatTime
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:
-
printMessage
Prints a message to a PrintStream.- Parameters:
message
- The message to print. Should not benull
.stream
- A PrintStream to print the message to. Must not benull
.priority
- The priority of the message. (Ignored in this implementation.)
-
log
Empty implementation which allows subclasses to receive the same output that is generated here.- Parameters:
message
- Message being logged. Should not benull
.
-
getTimestamp
Get the current time.- Returns:
- the current time as a formatted string.
- Since:
- Ant1.7.1
-
extractProjectName
Get the project name or null- Parameters:
event
- the event- Returns:
- the project that raised this event
- Since:
- Ant1.7.1
-