From ant-dev-return-30898-qmlist-jakarta-archive-ant-dev=jakarta.apache.org@jakarta.apache.org Tue Apr 23 18:33:59 2002 Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 7178 invoked from network); 23 Apr 2002 18:33:58 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 23 Apr 2002 18:33:58 -0000 Received: (qmail 1396 invoked by uid 97); 23 Apr 2002 18:33:59 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 1342 invoked by uid 97); 23 Apr 2002 18:33:58 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 1331 invoked by uid 97); 23 Apr 2002 18:33:58 -0000 Date: 23 Apr 2002 18:33:52 -0000 Message-ID: <20020423183352.15351.qmail@icarus.apache.org> From: ehatcher@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/listener CommonsLoggingListener.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ehatcher 02/04/23 11:33:52 Modified: . build.xml Added: src/main/org/apache/tools/ant/listener CommonsLoggingListener.java Log: Commons Logging listener Gump alert: to get this built we need to have commons-logging.jar available, but without the bulid should work fine. Revision Changes Path 1.299 +10 -0 jakarta-ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-ant/build.xml,v retrieving revision 1.298 retrieving revision 1.299 diff -u -r1.298 -r1.299 --- build.xml 20 Apr 2002 13:57:28 -0000 1.298 +++ build.xml 23 Apr 2002 18:33:52 -0000 1.299 @@ -219,6 +219,10 @@ + + + @@ -371,6 +375,9 @@ + + @@ -603,6 +611,7 @@ + @@ -641,6 +650,7 @@ + 1.1 jakarta-ant/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java Index: CommonsLoggingListener.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.tools.ant.listener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogConfigurationException; import org.apache.commons.logging.LogFactory; import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.Project; import org.apache.tools.ant.Target; import org.apache.tools.ant.Task; /** * Jakarta Commons Logging listener. * Note: do not use the SimpleLog as your logger implementation as it * causes an infinite loop since it writes to System.err, which Ant traps * and reroutes to the logger/listener layer. * * @author Erik Hatcher * @since Ant 1.5 */ public class CommonsLoggingListener implements BuildListener { /** Indicates if the listener was initialized. */ private boolean initialized = false; private LogFactory logFactory; /** * Construct the listener and make sure that a LogFactory * can be obtained. */ public CommonsLoggingListener() { try { logFactory = LogFactory.getFactory(); } catch (LogConfigurationException e) { e.printStackTrace(System.err); return; } initialized = true; } /** * @see BuildListener#buildStarted */ public void buildStarted(BuildEvent event) { if (initialized) { Log log = logFactory.getInstance(Project.class); log.info("Build started."); } } /** * @see BuildListener#buildFinished */ public void buildFinished(BuildEvent event) { if (initialized) { Log log = logFactory.getInstance(Project.class); if (event.getException() == null) { log.info("Build finished."); } else { log.error("Build finished with error.", event.getException()); } } } /** * @see BuildListener#targetStarted */ public void targetStarted(BuildEvent event) { if (initialized) { Log log = logFactory.getInstance(Target.class); log.info("Target \"" + event.getTarget().getName() + "\" started."); } } /** * @see BuildListener#targetFinished */ public void targetFinished(BuildEvent event) { if (initialized) { String targetName = event.getTarget().getName(); Log log = logFactory.getInstance(Target.class); if (event.getException() == null) { log.info("Target \"" + targetName + "\" finished."); } else { log.error("Target \"" + targetName + "\" finished with error.", event.getException()); } } } /** * @see BuildListener#taskStarted */ public void taskStarted(BuildEvent event) { if (initialized) { Task task = event.getTask(); Log log = logFactory.getInstance(task.getClass().getName()); log.info("Task \"" + task.getTaskName() + "\" started."); } } /** * @see BuildListener#taskFinished */ public void taskFinished(BuildEvent event) { if (initialized) { Task task = event.getTask(); Log log = logFactory.getInstance(task.getClass().getName()); if (event.getException() == null) { log.info("Task \"" + task.getTaskName() + "\" finished."); } else { log.error("Task \"" + task.getTaskName() + "\" finished with error.", event.getException()); } } } /** * @see BuildListener#messageLogged */ public void messageLogged(BuildEvent event) { if (initialized) { Object categoryObject = event.getTask(); if (categoryObject == null) { categoryObject = event.getTarget(); if (categoryObject == null) { categoryObject = event.getProject(); } } Log log = logFactory.getInstance(categoryObject.getClass().getName()); switch (event.getPriority()) { case Project.MSG_ERR: log.error(event.getMessage()); break; case Project.MSG_WARN: log.warn(event.getMessage()); break; case Project.MSG_INFO: log.info(event.getMessage()); break; case Project.MSG_VERBOSE: log.debug(event.getMessage()); break; case Project.MSG_DEBUG: log.debug(event.getMessage()); break; default: log.error(event.getMessage()); break; } } } } -- To unsubscribe, e-mail: For additional commands, e-mail: