logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From LAMY Olivier <LAMY_Oliv...@accor-hotels.com>
Subject new filter
Date Wed, 30 Oct 2002 16:51:48 GMT
sample in the config file
<filter class="org.apache.log4j.varia.FilterOnClasses ">
<param name="ClassList" value=" com.accor.util.sql.SqlTools,
com.accor.OTAebAdmin.bean.partenaires.OTAPartenaires"/>
<param name="MinimumLevel" value="ERROR"/>
</filter>

the class :
package org.apache.log4j.varia;
import java.util.HashSet;
import java.util.StringTokenizer;
import org.apache.log4j.Level;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
/**
* The filter admits two options <b>ClassList</b> et <b>MinimumLevel</b>
* <p>if the log event is in the class list and his level is greater than the
MinimumLevel {@link Filter#ACCEPT}is returned else {@link Filter#DENY} is
returned </p>
* <p>if the log event is not in the class list {@link Filter#NEUTRAL} is
returned
* @author Olivier Lamy
*
*/
public class FilterOnClasses extends Filter {
/** a string contained the class separated by a comma*/
String ClassList;
/** HashSet which contains all the classes to filter */
private HashSet ClassesHashSet;
/** minimum level */
Level minimumLevel;
/**
* Constructor for Log4jFilterOnClass.
*/
/*public Log4jFilterOnClass() {
super();
}*/
/**
* Return the decision of this filter.
* @see org.apache.log4j.spi.Filter#decide(LoggingEvent)
*/
public int decide(LoggingEvent event) {
if (this.ClassesHashSet.contains(event.getLoggerName())) {
/** logger is in the filter list next step test on the level */
if (event.getLevel().isGreaterOrEqual(minimumLevel) == false) return
Filter.DENY;
return Filter.ACCEPT;
}
return Filter.NEUTRAL;
}
/**
* Returns the classList.
* @return String
*/
public String getClassList() {
return ClassList;
}
/**
* Returns the minimumLevel.
* @return Level
*/
public Level getMinimumLevel() {
return minimumLevel;
}
/**
* Sets the classList.
* @param classList The classList to set
*/
public void setClassList(String classList) {
ClassList= classList;
StringTokenizer classesStringTokenizer = new StringTokenizer(classList,",");
this.ClassesHashSet = new HashSet(classesStringTokenizer.countTokens());
while (classesStringTokenizer.hasMoreTokens()) {
this.ClassesHashSet.add(classesStringTokenizer.nextToken().trim());
}
}
/**
* Sets the minimumLevel.
* @param minimumLevel The minimumLevel to set
*/
public void setMinimumLevel(Level minimumLevel) {
this.minimumLevel= minimumLevel;
}
}



	
**********************************************************************  
Ce message électronique et tous les fichiers joints ainsi que  les
informations contenues dans ce message (ci après "le message"), sont
confidentiels et destinés exclusivement à l'usage de la  personne à laquelle
ils sont adressés. Si vous avez reçu ce message par erreur, merci  de le
renvoyer à son émetteur et de le détruire. Toute diffusion, publication,
totale ou partielle ou divulgation sous quelque forme que ce soit non
expressément autorisées de ce message, sont interdites.  
	
**********************************************************************  
This e-mail, any attachments and the information contained (herein " the
message") are confidential and intended solely for the use of the
addressee(s) if you have received this message in error please send it back
to the sender and delete it. Unauthorized publication, use, dissemination or
disclosure, either whole or partial, of this  message is strictly
prohibited.

--
To unsubscribe, e-mail:   <mailto:log4j-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-dev-help@jakarta.apache.org>


Mime
View raw message