Hi,

As this is the first time sending mail to this dev-list, please do not
hesitate to tell me what I am doing wrong.

Based on the StringMatchFilter implementation a friend of mine (Bijan
Fathi) has created the attached LoggerMatchFilter. It uses the
logger's fqdn and acts similar to the StringMatchFilter.

Motivation:
In our project we use different appenders for different applications,
using a single log4j.xml (jboss, tclfilter). It was necessary to
filter loggers of a specific package, without interfering with other
appenders.

Strangely enough we could not find anything related, so we created this filter.

Was there already anything related we could have used? Is this approach ok?

Greetings,
Kariem
Index: log4j/src/java/org/apache/log4j/filter/LoggerMatchFilter.java
===================================================================
--- log4j/src/java/org/apache/log4j/filter/LoggerMatchFilter.java       
(revision 0)
+++ log4j/src/java/org/apache/log4j/filter/LoggerMatchFilter.java       
(revision 0)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.filter.StringMatchFilter;
+
+/**
+ * This is a very simple filter based on string matching on the logger fqdn.
+ * 
+ * @author Bijan Fathi
+ * @see StringMatchFilter
+ */
+public class LoggerMatchFilter extends StringMatchFilter {
+
+    public int decide(LoggingEvent event) {
+        String msg = event.fqnOfCategoryClass;
+
+        if (msg == null || getStringToMatch() == null) {
+            return Filter.NEUTRAL;
+        }
+
+        if (msg.indexOf(getStringToMatch()) == -1) {
+            // string not found
+            return Filter.NEUTRAL;
+        }
+        
+        // we've got a match
+        if (getAcceptOnMatch()) {
+            return Filter.ACCEPT;
+        }
+        return Filter.DENY;
+    }
+    
+}











---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to