logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1400886 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/spi/ api/src/test/java/org/apache/logging/log4j/ core/src/test/java/org/apache/logging/log4j/core/
Date Mon, 22 Oct 2012 14:08:12 GMT
Author: ggregory
Date: Mon Oct 22 14:08:12 2012
New Revision: 1400886

URL: http://svn.apache.org/viewvc?rev=1400886&view=rev
Log:
Add Logger.isEnabled(Level), should be like v1's Category.isEnabledFor(Priority).

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java?rev=1400886&r1=1400885&r2=1400886&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java Mon
Oct 22 14:08:12 2012
@@ -588,6 +588,15 @@ public interface Logger {
   boolean isDebugEnabled(Marker marker);
 
   /**
+   * Checks whether this Logger is enabled for the the given Level.
+   * 
+   * @param level
+   *            the level to check
+   * @return boolean - <code>true</code> if this Logger is enabled for level,
<code>false</code> otherwise.
+   */
+  boolean isEnabled(Level level);
+  
+  /**
    * Checks whether this Logger is enabled for the {@link Level#ERROR ERROR} Level.
    *
    * @return boolean - <code>true</code> if this Logger is enabled for level

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java?rev=1400886&r1=1400885&r2=1400886&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
Mon Oct 22 14:08:12 2012
@@ -917,6 +917,7 @@ public abstract class AbstractLogger imp
         return isEnabled(Level.WARN, null, (Object) null, null);
     }
 
+
     /**
      * Checks whether this Logger is enabled for the WARN Level.
      *
@@ -1427,6 +1428,17 @@ public abstract class AbstractLogger imp
     protected abstract boolean isEnabled(Level level, Marker marker, Object data, Throwable
t);
 
     /**
+     * Checks whether this Logger is enabled for the the given Level.
+     * 
+     * @param level
+     *            the level to check
+     * @return boolean - <code>true</code> if this Logger is enabled for level,
<code>false</code> otherwise.
+     */
+    public boolean isEnabled(Level level) {
+        return isEnabled(level, null, (Object) null, null);
+    }
+
+    /**
      * Determine if logging is enabled.
      * @param level The logging Level to check.
      * @param marker A Marker or null.

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1400886&r1=1400885&r2=1400886&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Mon Oct 22 14:08:12 2012
@@ -118,6 +118,52 @@ public class LoggerTest {
     }
 
     @Test
+    public void isAllEnabled() {
+        assertTrue("Incorrect level", logger.isEnabled(Level.ALL));
+    }
+
+    @Test
+    public void isDebugEnabled() {
+        assertTrue("Incorrect level", logger.isDebugEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.DEBUG));
+    }
+
+    @Test
+    public void isErrorEnabled() {
+        assertTrue("Incorrect level", logger.isErrorEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.ERROR));
+    }
+
+    @Test
+    public void isFatalEnabled() {
+        assertTrue("Incorrect level", logger.isFatalEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.FATAL));
+    }
+
+    @Test
+    public void isInfoEnabled() {
+        assertTrue("Incorrect level", logger.isInfoEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.INFO));
+    }
+
+    @Test
+    public void isOffEnabled() {
+        assertTrue("Incorrect level", logger.isEnabled(Level.OFF));
+    }
+
+    @Test
+    public void isTraceEnabled() {
+        assertTrue("Incorrect level", logger.isTraceEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.TRACE));
+    }
+
+    @Test
+    public void isWarnEnabled() {
+        assertTrue("Incorrect level", logger.isWarnEnabled());
+        assertTrue("Incorrect level", logger.isEnabled(Level.WARN));
+    }
+
+    @Test
     public void mdc() {
 
         ThreadContext.put("TestYear", new Integer(2010).toString());

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java?rev=1400886&r1=1400885&r2=1400886&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
Mon Oct 22 14:08:12 2012
@@ -83,6 +83,19 @@ public class SimplePerfTest {
     }
 
     @Test
+    public void debugDisabledByLevel() {
+        System.gc();
+        Timer timer = new Timer("DebugDisabled", LOOP_CNT);
+        timer.start();
+        for (int i=0; i < LOOP_CNT; ++i) {
+            logger.isEnabled(Level.DEBUG);
+        }
+        timer.stop();
+        System.out.println(timer.toString());
+        assertTrue("Timer exceeded max time of " + maxTime, maxTime > timer.getElapsedNanoTime());
+    }
+
+    @Test
     public void debugLogger() {
         System.gc();
         Timer timer = new Timer("DebugLogger", LOOP_CNT);



Mime
View raw message