KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > listener > TimestampedLogger


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.listener;
20
21 import org.apache.tools.ant.DefaultLogger;
22
23 import java.util.Date JavaDoc;
24 import java.text.DateFormat JavaDoc;
25
26 /**
27  * Like a normal logger, except with timed outputs
28  */

29 public class TimestampedLogger extends DefaultLogger {
30
31     /**
32      * what appears between the old message and the new
33      */

34     private static final String JavaDoc SPACER = " - at ";
35
36
37     /**
38      * This is an override point: the message that indicates whether a build failed.
39      * Subclasses can change/enhance the message.
40      *
41      * @return The classic "BUILD FAILED"
42      */

43     protected String JavaDoc getBuildFailedMessage() {
44         return super.getBuildFailedMessage() + SPACER + getTimestamp();
45     }
46
47     /**
48      * This is an override point: the message that indicates that a build succeeded.
49      * Subclasses can change/enhance the message.
50      *
51      * @return The classic "BUILD SUCCESSFUL"
52      */

53     protected String JavaDoc getBuildSuccessfulMessage() {
54         return super.getBuildSuccessfulMessage() + SPACER + getTimestamp();
55     }
56
57     /**
58      * Get the current time.
59      * @return the current time as a formatted string.
60      */

61     protected String JavaDoc getTimestamp() {
62         Date JavaDoc date = new Date JavaDoc(System.currentTimeMillis());
63         DateFormat JavaDoc formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
64         String JavaDoc finishTime = formatter.format(date);
65         return finishTime;
66     }
67 }
68
Popular Tags