/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included  with this distribution in
 * the LICENSE.APL file.
 */

package org.apache.log4j.varia;

import java.util.Vector;
import org.apache.log4j.spi.LoggingEvent;

/**
  Matches the logger names of events against a list of configured logger names.
  
  @author Mark Womack
*/
public class LoggerNameMatchFilter extends GenericMatchFilter {
  protected Vector nameArray = new Vector();
  
  public LoggerNameMatchFilter() {};
  
  /**
    Adds a logger name to an array used to test the event names for a match. */
  public
  void setLoggerName(String loggerName) {
	nameArray.add(loggerName);
  }
  
  /**
    Return true, can always attempt a match. */
  protected
  boolean canMatch() {
	return true;
  }
    
  /**
    Check to see if any of the configured logger names start with the event category name. */
  protected
  boolean match(LoggingEvent event) {
	int size = nameArray.size();
	for (int x = 0; x < size; x++) {
		if (((String)nameArray.elementAt(x)).startsWith(event.categoryName))
			return true;
	}
	
	return false;
  }

}