git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278517 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -256,6 +256,9 @@ Other changes: | |||
| * <javadoc> now supports -breakiterator for custom doclets if Ant is | |||
| running on JSE 5.0 or higher. Bugzilla Report: 34580. | |||
| * New logger, TimestampedLogger, that prints the wall time that a build finished/failed | |||
| Use with -logger org.apache.tools.ant.listener.TimestampedLogger | |||
| Changes from Ant 1.6.4 to Ant 1.6.5 | |||
| =================================== | |||
| @@ -83,6 +83,12 @@ listeners and loggers.</p> | |||
| <td width="33%">Writes the build information to an XML file.</td> | |||
| <td width="34%">BuildLogger</td> | |||
| </tr> | |||
| <tr> | |||
| <td width="33%"><code><a href="#TimestampedLogger">org.apache.tools.ant.TimestampedLogger</a></code></td> | |||
| <td width="33%">Prints the time that a build finished</td> | |||
| <td width="34%">BuildLogger</td> | |||
| </tr> | |||
| </table> | |||
| <h3><a name="DefaultLogger">DefaultLogger</a></h3> | |||
| @@ -313,19 +319,33 @@ ANT_HOME/etc for one of these. You can set the property | |||
| this can be a relative or absolute file path, or an http URL. | |||
| If you set the property to the empty string, "", no XSLT transform | |||
| is declared at all. | |||
| </p> | |||
| <blockquote> | |||
| <p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br> | |||
| <code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p> | |||
| </blockquote> | |||
| <h3><a name="TimestampedLogger">TimestampedLogger</a></h3> | |||
| <p> | |||
| Acts like the default logger, except that the final success/failure message also includes | |||
| the time that the build completed. For example: | |||
| </p> | |||
| <pre> | |||
| BUILD SUCCESSFUL - at 16/08/05 16:24 | |||
| </pre> | |||
| <blockquote> | |||
| <p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br> | |||
| <code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p> | |||
| <code>ant -logger org.apache.tools.ant.listener.TimestampedLogger</code> | |||
| </blockquote> | |||
| <h2><a name="dev">Writing your own</a></h2> | |||
| <p>See the <a href="develop.html#buildevents">Build Events</a> section for | |||
| @@ -21,6 +21,7 @@ import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.PrintStream; | |||
| import java.io.StringReader; | |||
| import org.apache.tools.ant.util.DateUtils; | |||
| import org.apache.tools.ant.util.StringUtils; | |||
| @@ -131,24 +132,19 @@ public class DefaultLogger implements BuildLogger { | |||
| public void buildFinished(BuildEvent event) { | |||
| Throwable error = event.getException(); | |||
| StringBuffer message = new StringBuffer(); | |||
| if (error == null) { | |||
| message.append(StringUtils.LINE_SEP); | |||
| message.append("BUILD SUCCESSFUL"); | |||
| message.append(getBuildSuccessfulMessage()); | |||
| } else { | |||
| message.append(StringUtils.LINE_SEP); | |||
| message.append("BUILD FAILED"); | |||
| message.append(getBuildFailedMessage()); | |||
| message.append(StringUtils.LINE_SEP); | |||
| if (Project.MSG_VERBOSE <= msgOutputLevel | |||
| || !(error instanceof BuildException)) { | |||
| message.append(StringUtils.getStackTrace(error)); | |||
| } else { | |||
| if (error instanceof BuildException) { | |||
| message.append(error.toString()).append(lSep); | |||
| } else { | |||
| message.append(error.getMessage()).append(lSep); | |||
| } | |||
| message.append(error.toString()).append(lSep); | |||
| } | |||
| } | |||
| message.append(StringUtils.LINE_SEP); | |||
| @@ -164,6 +160,24 @@ public class DefaultLogger implements BuildLogger { | |||
| log(msg); | |||
| } | |||
| /** | |||
| * This is an override point: the message that indicates whether a build failed. | |||
| * Subclasses can change/enhance the message. | |||
| * @return The classic "BUILD FAILED" | |||
| */ | |||
| protected String getBuildFailedMessage() { | |||
| return "BUILD FAILED"; | |||
| } | |||
| /** | |||
| * This is an override point: the message that indicates that a build succeeded. | |||
| * Subclasses can change/enhance the message. | |||
| * @return The classic "BUILD SUCCESSFUL" | |||
| */ | |||
| protected String getBuildSuccessfulMessage() { | |||
| return "BUILD SUCCESSFUL"; | |||
| } | |||
| /** | |||
| * Logs a message to say that the target has started if this | |||
| * logger allows information-level messages. | |||
| @@ -57,6 +57,15 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| private LogFactory logFactory; | |||
| /** | |||
| * name of the category under which target events are logged | |||
| */ | |||
| public static final String TARGET_LOG = "org.apache.tools.ant.Target"; | |||
| /** | |||
| * name of the category under which project events are logged | |||
| */ | |||
| public static final String PROJECT_LOG = "org.apache.tools.ant.Project"; | |||
| /** | |||
| * Construct the listener and make sure that a LogFactory | |||
| * can be obtained. | |||
| @@ -95,7 +104,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| * @see BuildListener#buildStarted | |||
| */ | |||
| public void buildStarted(BuildEvent event) { | |||
| String categoryString = "org.apache.tools.ant.Project"; | |||
| String categoryString = PROJECT_LOG; | |||
| Log log = getLog(categoryString, null); | |||
| if (initialized) { | |||
| @@ -108,7 +117,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| */ | |||
| public void buildFinished(BuildEvent event) { | |||
| if (initialized) { | |||
| String categoryString = "org.apache.tools.ant.Project"; | |||
| String categoryString = PROJECT_LOG; | |||
| Log log = getLog(categoryString, event.getProject().getName()); | |||
| if (event.getException() == null) { | |||
| @@ -125,7 +134,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| */ | |||
| public void targetStarted(BuildEvent event) { | |||
| if (initialized) { | |||
| Log log = getLog("org.apache.tools.ant.Target", | |||
| Log log = getLog(TARGET_LOG, | |||
| event.getTarget().getName()); | |||
| // Since task log category includes target, we don't really | |||
| // need this message | |||
| @@ -140,7 +149,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| public void targetFinished(BuildEvent event) { | |||
| if (initialized) { | |||
| String targetName = event.getTarget().getName(); | |||
| Log log = getLog("org.apache.tools.ant.Target", | |||
| Log log = getLog(TARGET_LOG, | |||
| event.getTarget().getName()); | |||
| if (event.getException() == null) { | |||
| realLog(log, "Target end: " + targetName, Project.MSG_DEBUG, null); | |||
| @@ -214,10 +223,10 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
| categoryObject = event.getTarget(); | |||
| if (categoryObject == null) { | |||
| categoryObject = event.getProject(); | |||
| categoryString = "org.apache.tools.ant.Project"; | |||
| categoryString = PROJECT_LOG; | |||
| categoryDetail = event.getProject().getName(); | |||
| } else { | |||
| categoryString = "org.apache.tools.ant.Target"; | |||
| categoryString = TARGET_LOG; | |||
| categoryDetail = event.getTarget().getName(); | |||
| } | |||
| } else { | |||
| @@ -35,12 +35,17 @@ public class Log4jListener implements BuildListener { | |||
| /** Indicates if the listener was initialized. */ | |||
| private boolean initialized = false; | |||
| /** | |||
| * log category we log into | |||
| */ | |||
| public static final String LOG_ANT = "org.apache.tools.ant"; | |||
| /** | |||
| * Construct the listener and make sure there is a valid appender. | |||
| */ | |||
| public Log4jListener() { | |||
| initialized = false; | |||
| Logger log = Logger.getLogger("org.apache.tools.ant"); | |||
| Logger log = Logger.getLogger(LOG_ANT); | |||
| Logger rootLog = Logger.getRootLogger(); | |||
| if (!(rootLog.getAllAppenders() instanceof NullEnumeration)) { | |||
| initialized = true; | |||
| @@ -0,0 +1,45 @@ | |||
| package org.apache.tools.ant.listener; | |||
| import org.apache.tools.ant.DefaultLogger; | |||
| import java.util.Date; | |||
| import java.text.DateFormat; | |||
| /** | |||
| * Like a normal logger, except with timed outputs | |||
| */ | |||
| public class TimestampedLogger extends DefaultLogger { | |||
| /** | |||
| * what appears between the old message and the new | |||
| */ | |||
| private static final String SPACER = " - at "; | |||
| /** | |||
| * This is an override point: the message that indicates whether a build failed. | |||
| * Subclasses can change/enhance the message. | |||
| * | |||
| * @return The classic "BUILD FAILED" | |||
| */ | |||
| protected String getBuildFailedMessage() { | |||
| return super.getBuildFailedMessage() + SPACER + getTimestamp(); | |||
| } | |||
| /** | |||
| * This is an override point: the message that indicates that a build succeeded. | |||
| * Subclasses can change/enhance the message. | |||
| * | |||
| * @return The classic "BUILD SUCCESSFUL" | |||
| */ | |||
| protected String getBuildSuccessfulMessage() { | |||
| return super.getBuildSuccessfulMessage()+SPACER +getTimestamp(); | |||
| } | |||
| protected String getTimestamp() { | |||
| Date date = new Date(System.currentTimeMillis()); | |||
| DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); | |||
| String finishTime = formatter.format(date); | |||
| return finishTime; | |||
| } | |||
| } | |||