1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2012 Sabre Holdings. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.ant.utils; 20 21 import java.text.SimpleDateFormat; 22 import java.util.Date; 23 24 import org.apache.tools.ant.Task; 25 26 /** 27 * Provides logging functionality for classes without access to the Ant project 28 * variable. 29 * 30 */ 31 public class TaskLog 32 { 33 34 private static Task task; 35 36 private static final SimpleDateFormat format = new SimpleDateFormat( 37 "yyyy-MM-dd HH:mm:ss.SSS"); 38 39 public static void setTask(Task task) 40 { 41 TaskLog.task = task; 42 } 43 44 public static void log(String message) 45 { 46 task.log(message); 47 } 48 49 public static void logWithTimestamp(String message) 50 { 51 String date; 52 synchronized (format) 53 { 54 date = format.format(new Date()); 55 } 56 task.log(date + ": " + message); 57 } 58 }