[jboss-svn-commits] JBoss Common SVN: r3318 - in jboss-logmanager/trunk/src: test/java/org/jboss/logmanager and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jun 29 18:51:23 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-06-29 18:51:22 -0400 (Mon, 29 Jun 2009)
New Revision: 3318
Added:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelFilter.java
Removed:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelExcludingFilter.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelIncludingFilter.java
Modified:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/RegexFilter.java
jboss-logmanager/trunk/src/test/java/org/jboss/logmanager/FilterTests.java
Log:
More consistent filter classes; rely on InvertFilter rather than providing inverting and non-inverting variations on everything
Deleted: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelExcludingFilter.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelExcludingFilter.java 2009-06-25 03:17:46 UTC (rev 3317)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelExcludingFilter.java 2009-06-29 22:51:22 UTC (rev 3318)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.logmanager.filters;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import java.util.logging.Filter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * A filter which excludes messages of a certain level or levels
- */
-public final class LevelExcludingFilter implements Filter {
- private final Set<Level> excludedLevels;
-
- /**
- * Construct a new instance.
- *
- * @param excludedLevel the level to exclude
- */
- public LevelExcludingFilter(final Level excludedLevel) {
- excludedLevels = Collections.singleton(excludedLevel);
- }
-
- /**
- * Construct a new instance.
- *
- * @param excludedLevels the levels to exclude
- */
- public LevelExcludingFilter(final Collection<Level> excludedLevels) {
- this.excludedLevels = new HashSet<Level>(excludedLevels);
- }
-
- /**
- * Determine whether the message is loggable.
- *
- * @param record the log record
- * @return {@code true} if the level is not in the exclusion list
- */
- public boolean isLoggable(final LogRecord record) {
- return ! excludedLevels.contains(record.getLevel());
- }
-}
Copied: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelFilter.java (from rev 3304, jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelIncludingFilter.java)
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelFilter.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelFilter.java 2009-06-29 22:51:22 UTC (rev 3318)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.logmanager.filters;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import java.util.logging.Filter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * A filter which excludes messages of a certain level or levels
+ */
+public final class LevelFilter implements Filter {
+ private final Set<Level> includedLevels;
+
+ /**
+ * Construct a new instance.
+ *
+ * @param includedLevel the level to include
+ */
+ public LevelFilter(final Level includedLevel) {
+ includedLevels = Collections.singleton(includedLevel);
+ }
+
+ /**
+ * Construct a new instance.
+ *
+ * @param includedLevels the levels to exclude
+ */
+ public LevelFilter(final Collection<Level> includedLevels) {
+ this.includedLevels = new HashSet<Level>(includedLevels);
+ }
+
+ /**
+ * Determine whether the message is loggable.
+ *
+ * @param record the log record
+ * @return {@code true} if the level is in the inclusion list
+ */
+ public boolean isLoggable(final LogRecord record) {
+ return includedLevels.contains(record.getLevel());
+ }
+}
\ No newline at end of file
Deleted: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelIncludingFilter.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelIncludingFilter.java 2009-06-25 03:17:46 UTC (rev 3317)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/LevelIncludingFilter.java 2009-06-29 22:51:22 UTC (rev 3318)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.logmanager.filters;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import java.util.logging.Filter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * A filter which excludes messages of a certain level or levels
- */
-public final class LevelIncludingFilter implements Filter {
- private final Set<Level> includedLevels;
-
- /**
- * Construct a new instance.
- *
- * @param includedLevel the level to include
- */
- public LevelIncludingFilter(final Level includedLevel) {
- includedLevels = Collections.singleton(includedLevel);
- }
-
- /**
- * Construct a new instance.
- *
- * @param includedLevels the levels to exclude
- */
- public LevelIncludingFilter(final Collection<Level> includedLevels) {
- this.includedLevels = new HashSet<Level>(includedLevels);
- }
-
- /**
- * Determine whether the message is loggable.
- *
- * @param record the log record
- * @return {@code true} if the level is in the inclusion list
- */
- public boolean isLoggable(final LogRecord record) {
- return includedLevels.contains(record.getLevel());
- }
-}
\ No newline at end of file
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/RegexFilter.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/RegexFilter.java 2009-06-25 03:17:46 UTC (rev 3317)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/filters/RegexFilter.java 2009-06-29 22:51:22 UTC (rev 3318)
@@ -33,27 +33,23 @@
*/
public final class RegexFilter implements Filter {
private final Pattern pattern;
- private final boolean exclude;
/**
* Create a new instance.
*
* @param pattern the pattern to match
- * @param exclude {@code true} if matching records should be excluded, {@code false} if matching records should be included
*/
- public RegexFilter(final Pattern pattern, final boolean exclude) {
+ public RegexFilter(final Pattern pattern) {
this.pattern = pattern;
- this.exclude = exclude;
}
/**
* Create a new instance.
*
* @param patternString the pattern string to match
- * @param exclude {@code true} if matching records should be excluded, {@code false} if matching records should be included
*/
- public RegexFilter(final String patternString, final boolean exclude) {
- this(Pattern.compile(patternString), exclude);
+ public RegexFilter(final String patternString) {
+ this(Pattern.compile(patternString));
}
/**
@@ -63,6 +59,6 @@
* @return {@code true} if the log record is loggable
*/
public boolean isLoggable(final LogRecord record) {
- return pattern.matcher(record.getMessage()).find() != exclude;
+ return pattern.matcher(record.getMessage()).find();
}
}
Modified: jboss-logmanager/trunk/src/test/java/org/jboss/logmanager/FilterTests.java
===================================================================
--- jboss-logmanager/trunk/src/test/java/org/jboss/logmanager/FilterTests.java 2009-06-25 03:17:46 UTC (rev 3317)
+++ jboss-logmanager/trunk/src/test/java/org/jboss/logmanager/FilterTests.java 2009-06-29 22:51:22 UTC (rev 3318)
@@ -30,8 +30,7 @@
import org.jboss.logmanager.filters.AnyFilter;
import org.jboss.logmanager.filters.InvertFilter;
import org.jboss.logmanager.filters.LevelChangingFilter;
-import org.jboss.logmanager.filters.LevelExcludingFilter;
-import org.jboss.logmanager.filters.LevelIncludingFilter;
+import org.jboss.logmanager.filters.LevelFilter;
import org.jboss.logmanager.filters.LevelRangeFilter;
import org.jboss.logmanager.filters.RegexFilter;
import org.jboss.logmanager.filters.SubstituteFilter;
@@ -272,8 +271,8 @@
assertFalse("Handler was run", ran.get());
}
- public void testLevelExcludingFilter0() {
- final Filter filter = new LevelExcludingFilter(Level.INFO);
+ public void testLevelFilter0() {
+ final Filter filter = new LevelFilter(Level.INFO);
final AtomicBoolean ran = new AtomicBoolean();
final Handler handler = new CheckingHandler(ran);
final Logger logger = Logger.getLogger("filterTest");
@@ -283,25 +282,11 @@
logger.setFilter(filter);
handler.setLevel(Level.INFO);
logger.info("This is a test.");
- assertFalse("Handler was run", ran.get());
- }
-
- public void testLevelExcludingFilter1() {
- final Filter filter = new LevelExcludingFilter(Level.WARNING);
- final AtomicBoolean ran = new AtomicBoolean();
- final Handler handler = new CheckingHandler(ran);
- final Logger logger = Logger.getLogger("filterTest");
- logger.setUseParentHandlers(false);
- logger.addHandler(handler);
- logger.setLevel(Level.INFO);
- logger.setFilter(filter);
- handler.setLevel(Level.INFO);
- logger.info("This is a test.");
assertTrue("Handler wasn't run", ran.get());
}
- public void testLevelIncludingFilter0() {
- final Filter filter = new LevelIncludingFilter(Level.INFO);
+ public void testLevelFilter1() {
+ final Filter filter = new LevelFilter(Level.WARNING);
final AtomicBoolean ran = new AtomicBoolean();
final Handler handler = new CheckingHandler(ran);
final Logger logger = Logger.getLogger("filterTest");
@@ -311,20 +296,6 @@
logger.setFilter(filter);
handler.setLevel(Level.INFO);
logger.info("This is a test.");
- assertTrue("Handler wasn't run", ran.get());
- }
-
- public void testLevelIncludingFilter1() {
- final Filter filter = new LevelIncludingFilter(Level.WARNING);
- final AtomicBoolean ran = new AtomicBoolean();
- final Handler handler = new CheckingHandler(ran);
- final Logger logger = Logger.getLogger("filterTest");
- logger.setUseParentHandlers(false);
- logger.addHandler(handler);
- logger.setLevel(Level.INFO);
- logger.setFilter(filter);
- handler.setLevel(Level.INFO);
- logger.info("This is a test.");
assertFalse("Handler was run", ran.get());
}
@@ -357,7 +328,7 @@
}
public void testRegexFilter0() {
- final Filter filter = new RegexFilter("test", true);
+ final Filter filter = new RegexFilter("test");
final AtomicBoolean ran = new AtomicBoolean();
final Handler handler = new CheckingHandler(ran);
final Logger logger = Logger.getLogger("filterTest");
@@ -367,11 +338,11 @@
logger.setFilter(filter);
handler.setLevel(Level.INFO);
logger.info("This is a test.");
- assertFalse("Handler was run", ran.get());
+ assertTrue("Handler wasn't run", ran.get());
}
public void testRegexFilter1() {
- final Filter filter = new RegexFilter("test", true);
+ final Filter filter = new RegexFilter("pest");
final AtomicBoolean ran = new AtomicBoolean();
final Handler handler = new CheckingHandler(ran);
final Logger logger = Logger.getLogger("filterTest");
@@ -380,8 +351,8 @@
logger.setLevel(Level.INFO);
logger.setFilter(filter);
handler.setLevel(Level.INFO);
- logger.info("This is the best.");
- assertTrue("Handler wasn't run", ran.get());
+ logger.info("This is a test.");
+ assertFalse("Handler was run", ran.get());
}
public void testSubstitueFilter0() {
More information about the jboss-svn-commits
mailing list