logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1508665 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/status/ core/src/main/java/org/apache/logging/log4j/core/jmx/ src/changes/
Date Tue, 30 Jul 2013 22:15:27 GMT
Author: rgoers
Date: Tue Jul 30 22:15:27 2013
New Revision: 1508665

URL: http://svn.apache.org/r1508665
Log:
LOG4J2-329 - StatusLogger now only creates StatusData objects if they are the appropriate
logging level

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusListener.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java?rev=1508665&r1=1508664&r2=1508665&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
Tue Jul 30 22:15:27 2013
@@ -75,12 +75,20 @@ public class StatusConsoleListener imple
     }
 
     /**
+     * Return the Log Level for which the Listener should receive events.
+     * @return the Log Level.
+     */
+    public Level getStatusLevel() {
+        return this.level;
+    }
+
+    /**
      * Writes status messages to the console.
      * @param data The StatusData.
      */
     @Override
     public void log(final StatusData data) {
-        if (data.getLevel().isAtLeastAsSpecificAs(level) && !filtered(data)) {
+        if (!filtered(data)) {
             stream.println(data.getFormattedStatus());
         }
     }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusListener.java?rev=1508665&r1=1508664&r2=1508665&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusListener.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusListener.java
Tue Jul 30 22:15:27 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.status;
 
+import org.apache.logging.log4j.Level;
+
 /**
  * Interface that allows implementers to be notified of events in the logging system.
  */
@@ -26,4 +28,10 @@ public interface StatusListener {
      * @param data The StatusData for the event.
      */
     void log(StatusData data);
+
+    /**
+     * Return the Log Level that this listener wants included.
+     * @return the Log Level.
+     */
+    Level getStatusLevel();
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java?rev=1508665&r1=1508664&r2=1508665&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Tue Jul 30 22:15:27 2013
@@ -49,6 +49,8 @@ public final class StatusLogger extends 
 
     private static final int MAX_ENTRIES = PROPS.getIntegerProperty(MAX_STATUS_ENTRIES, 200);
 
+    private static final String DEFAULT_STATUS_LEVEL = PROPS.getStringProperty("log4j2.StatusLogger.level");
+
     // private static final String FQCN = AbstractLogger.class.getName();
 
     private static final StatusLogger STATUS_LOGGER = new StatusLogger();
@@ -61,9 +63,12 @@ public final class StatusLogger extends 
     private final Queue<StatusData> messages = new BoundedQueue<StatusData>(MAX_ENTRIES);
     private final ReentrantLock msgLock = new ReentrantLock();
 
+    private int listenersLevel;
+
     private StatusLogger() {
         this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, false, false,
"", null, PROPS,
             System.err);
+        this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel();
     }
 
     /**
@@ -90,6 +95,10 @@ public final class StatusLogger extends 
         listenersLock.writeLock().lock();
         try {
             listeners.add(listener);
+            Level lvl = listener.getStatusLevel();
+            if (listenersLevel < lvl.intLevel()) {
+                listenersLevel = lvl.intLevel();
+            }
         } finally {
             listenersLock.writeLock().unlock();
         }
@@ -103,6 +112,14 @@ public final class StatusLogger extends 
         listenersLock.writeLock().lock();
         try {
             listeners.remove(listener);
+            int lowest = Level.ERROR.intLevel();
+            for (StatusListener l : listeners) {
+                int level = l.getStatusLevel().intLevel();
+                if (lowest < level) {
+                    lowest = level;
+                }
+            }
+            listenersLevel = lowest;
         } finally {
             listenersLock.writeLock().unlock();
         }
@@ -173,7 +190,9 @@ public final class StatusLogger extends 
         }
         if (listeners.size() > 0) {
             for (final StatusListener listener : listeners) {
-                listener.log(data);
+                if (data.getLevel().isAtLeastAsSpecificAs(listener.getStatusLevel())) {
+                    listener.log(data);
+                }
             }
         } else {
             logger.log(marker, fqcn, level, msg, t);
@@ -227,7 +246,7 @@ public final class StatusLogger extends 
     @Override
     public boolean isEnabled(final Level level, final Marker marker) {
         if (listeners.size() > 0) {
-            return true;
+            return listenersLevel >= level.intLevel();
         }
         switch (level) {
             case FATAL:

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java?rev=1508665&r1=1508664&r2=1508665&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java
Tue Jul 30 22:15:27 2013
@@ -37,11 +37,12 @@ public class StatusLoggerAdmin extends N
 
     private final AtomicLong sequenceNo = new AtomicLong();
     private final ObjectName objectName;
+    private Level level = Level.WARN;
 
     /**
      * Constructs a new {@code StatusLoggerAdmin} with the {@code Executor} to
      * be used for sending {@code Notification}s asynchronously to listeners.
-     * 
+     *
      * @param executor used to send notifications asynchronously
      */
     public StatusLoggerAdmin(final Executor executor) {
@@ -79,17 +80,22 @@ public class StatusLoggerAdmin extends N
 
     @Override
     public String getLevel() {
-        return StatusLogger.getLogger().getLevel().name();
+        return this.level.name();
+    }
+
+    @Override
+    public Level getStatusLevel() {
+        return this.level;
     }
 
     @Override
     public void setLevel(final String level) {
-        StatusLogger.getLogger().setLevel(Level.valueOf(level));
+        this.level = Level.toLevel(level, Level.ERROR);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.apache.logging.log4j.status.StatusListener#log(org.apache.logging
      * .log4j.status.StatusData)
@@ -108,7 +114,7 @@ public class StatusLoggerAdmin extends N
 
     /**
      * Returns the {@code ObjectName} of this mbean.
-     * 
+     *
      * @return the {@code ObjectName}
      * @see StatusLoggerAdminMBean#NAME
      */

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1508665&r1=1508664&r2=1508665&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Jul 30 22:15:27 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-329" dev="rgoers" type="fix">
+        StatusLogger now only creates StatusData objects if they are the appropriate logging
level.
+      </action>
       <action issue="LOG4J2-328" dev="rgoers" type="fix">
         FlumePersistentManager was calling Berkeley DB's count method too frequently.
       </action>



Mime
View raw message