View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.ant; 22 23 import java.io.File; 24 import java.net.URL; 25 26 import org.apache.log4j.Logger; 27 import org.apache.log4j.PropertyConfigurator; 28 import org.apache.tools.ant.BuildException; 29 30 31 /*** 32 * Configure Log4J from a property file. 33 * 34 * @version __VERSION__ 35 * 36 * @author __AUTHOR__ 37 */ 38 public class Log4jConfigTask extends org.apache.tools.ant.Task { 39 /*** 40 * The Log4J <code>Logger</code> doing the logging. 41 */ 42 protected static Logger logger = Logger.getLogger(Log4jConfigTask.class); 43 44 /* 45 * Properties 46 */ 47 48 /*** 49 * The name of the Log4J Property file. 50 */ 51 protected String propertyFile; 52 53 /* 54 * Constructors 55 */ 56 57 /*** 58 * Default Constructor 59 */ 60 public Log4jConfigTask() { 61 } 62 63 /*** 64 * Sets the name of the Property file to configure with. 65 */ 66 public void setPropertyFile(String propertyFile) { 67 logger.info("METHOD_ENTRY: setPropertyFile, propertyFile=" 68 + propertyFile); 69 70 System.out.println("propertyFile=" + propertyFile); 71 this.propertyFile = propertyFile; 72 } 73 74 /*** 75 * The Ant-defined <code>execute</code> method must be implemented by subclasses. 76 */ 77 public void execute() 78 throws BuildException { 79 try { 80 System.out.println(propertyFile); 81 82 File file = new File(propertyFile); 83 84 URL url = (URL) file.toURL(); 85 86 PropertyConfigurator.configure(url); 87 } catch (Exception e) { 88 e.printStackTrace(); 89 logger.error(e); 90 throw new BuildException(e.getMessage()); 91 } 92 } 93 }

This page was automatically generated by Maven