FileDocCategorySizeDatePackage
Log4jListener.javaAPI DocApache Ant 1.705767Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.listener

Log4jListener

public class Log4jListener extends Object implements org.apache.tools.ant.BuildListener
Listener which sends events to Log4j logging system

Fields Summary
private boolean
initialized
Indicates if the listener was initialized.
public static final String
LOG_ANT
log category we log into
Constructors Summary
public Log4jListener()
Construct the listener and make sure there is a valid appender.


                    
      
        initialized = false;
        Logger log = Logger.getLogger(LOG_ANT);
        Logger rootLog = Logger.getRootLogger();
        if (!(rootLog.getAllAppenders() instanceof NullEnumeration)) {
            initialized = true;
        } else {
            log.error("No log4j.properties in build area");
        }
    
Methods Summary
public voidbuildFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Logger log = Logger.getLogger(Project.class.getName());
            if (event.getException() == null) {
                log.info("Build finished.");
            } else {
                log.error("Build finished with error.", event.getException());
            }
        }
    
public voidbuildStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Logger log = Logger.getLogger(Project.class.getName());
            log.info("Build started.");
        }
    
public voidmessageLogged(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Object categoryObject = event.getTask();
            if (categoryObject == null) {
                categoryObject = event.getTarget();
                if (categoryObject == null) {
                    categoryObject = event.getProject();
                }
            }

            Logger log
                = Logger.getLogger(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;
            }
        }
    
public voidtargetFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            String targetName = event.getTarget().getName();
            Logger cat = Logger.getLogger(Target.class.getName());
            if (event.getException() == null) {
                cat.info("Target \"" + targetName + "\" finished.");
            } else {
                cat.error("Target \"" + targetName
                    + "\" finished with error.", event.getException());
            }
        }
    
public voidtargetStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Logger log = Logger.getLogger(Target.class.getName());
            log.info("Target \"" + event.getTarget().getName() + "\" started.");
        }
    
public voidtaskFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Task task = event.getTask();
            Logger log = Logger.getLogger(task.getClass().getName());
            if (event.getException() == null) {
                log.info("Task \"" + task.getTaskName() + "\" finished.");
            } else {
                log.error("Task \"" + task.getTaskName()
                    + "\" finished with error.", event.getException());
            }
        }
    
public voidtaskStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        if (initialized) {
            Task task = event.getTask();
            Logger log = Logger.getLogger(task.getClass().getName());
            log.info("Task \"" + task.getTaskName() + "\" started.");
        }