public class DefaultLogger extends java.lang.Object implements BuildLogger
Modifier and Type | Field and 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
Line separator
|
protected int |
msgOutputLevel
Lowest level of message to write out
|
protected java.io.PrintStream |
out
PrintStream to write non-error messages to
|
Constructor and Description |
---|
DefaultLogger()
Sole constructor.
|
Modifier and Type | Method and 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.
|
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.
|
public static final int LEFT_COLUMN_SIZE
messageLogged(BuildEvent)
,
Constant Field Valuesprotected java.io.PrintStream out
protected java.io.PrintStream err
protected int msgOutputLevel
protected static final java.lang.String lSep
protected boolean emacsMode
public void setMessageOutputLevel(int level)
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.
setMessageOutputLevel
in interface BuildLogger
level
- the logging level for the logger.public void setOutputPrintStream(java.io.PrintStream output)
setOutputPrintStream
in interface BuildLogger
output
- The output stream for the logger.
Must not be null
.public void setErrorPrintStream(java.io.PrintStream err)
setErrorPrintStream
in interface BuildLogger
err
- The error stream for the logger.
Must not be null
.public void setEmacsMode(boolean emacsMode)
setEmacsMode
in interface BuildLogger
emacsMode
- true
if output is to be unadorned so that
emacs and other editors can parse files names, etc.public void buildStarted(BuildEvent event)
buildStarted
in interface BuildListener
event
- Ignored.public void buildFinished(BuildEvent event)
buildFinished
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getException()
protected java.lang.String getBuildFailedMessage()
protected java.lang.String getBuildSuccessfulMessage()
public void targetStarted(BuildEvent event)
targetStarted
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getTarget()
public void targetFinished(BuildEvent event)
targetFinished
in interface BuildListener
event
- Ignored.BuildEvent.getException()
public void taskStarted(BuildEvent event)
taskStarted
in interface BuildListener
event
- Ignored.BuildEvent.getTask()
public void taskFinished(BuildEvent event)
taskFinished
in interface BuildListener
event
- Ignored.BuildEvent.getException()
public void messageLogged(BuildEvent event)
messageLogged
in interface BuildListener
event
- A BuildEvent containing message information.
Must not be null
.BuildEvent.getMessage()
,
BuildEvent.getException()
,
BuildEvent.getPriority()
protected static java.lang.String formatTime(long millis)
millis
- Length of time to format, in milliseconds.DateUtils.formatElapsedTime(long)
protected void printMessage(java.lang.String message, java.io.PrintStream stream, int priority)
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.)protected void log(java.lang.String message)
message
- Message being logged. Should not be null
.protected java.lang.String getTimestamp()
protected java.lang.String extractProjectName(BuildEvent event)
event
- the event