View Javadoc

1   // ========================================================================
2   // Copyright 2006-2007 Sabre Holdings.
3   // ------------------------------------------------------------------------
4   // Licensed under the Apache License, Version 2.0 (the "License");
5   // you may not use this file except in compliance with the License.
6   // You may obtain a copy of the License at
7   // http://www.apache.org/licenses/LICENSE-2.0
8   // Unless required by applicable law or agreed to in writing, software
9   // distributed under the License is distributed on an "AS IS" BASIS,
10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  // See the License for the specific language governing permissions and
12  // limitations under the License.
13  // ========================================================================
14  
15  package org.mortbay.jetty.ant.utils;
16  
17  import java.text.SimpleDateFormat;
18  import java.util.Date;
19  
20  import org.apache.tools.ant.Task;
21  
22  /**
23   * Provides logging functionality for classes without access to the Ant project
24   * variable.
25   * 
26   * @author Jakub Pawlowicz
27   */
28  public class TaskLog
29  {
30  
31      private static Task task;
32  
33      private static SimpleDateFormat format = new SimpleDateFormat(
34              "yyyy-MM-dd HH:mm:ss.SSS");
35  
36      public static void setTask(Task task)
37      {
38          TaskLog.task = task;
39      }
40  
41      public static void log(String message)
42      {
43          task.log(message);
44      }
45  
46      public static void logWithTimestamp(String message)
47      {
48          task.log(format.format(new Date()) + ": " + message);
49      }
50  }