sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1523611 - /sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java
Date Mon, 16 Sep 2013 12:28:15 GMT
Author: cziegeler
Date: Mon Sep 16 12:28:14 2013
New Revision: 1523611

URL: http://svn.apache.org/r1523611
Log:
SLING-3069 :  Allow attaching an Appender to a Logger without changing its existing Log level


Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java?rev=1523611&r1=1523610&r2=1523611&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/AppenderTracker.java
Mon Sep 16 12:28:14 2013
@@ -25,12 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.Appender;
-
 import org.apache.sling.commons.log.logback.internal.util.Util;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -39,6 +33,11 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.Appender;
+
 public class AppenderTracker extends ServiceTracker implements LogbackResetListener {
     private static final String PROP_LOGGER = "loggers";
 
@@ -85,38 +84,22 @@ public class AppenderTracker extends Ser
         return appenders.values();
     }
 
-    private void detachAppender(AppenderInfo ai) {
+    private void detachAppender(final AppenderInfo ai) {
         if (ai != null) {
-            for (LoggerInfo li : ai.loggers) {
-                Logger logger = loggerContext.getLogger(li.name);
-
-                // Reset values back to old ones if they match the
-                // ones we modified to
-                if (li.level.equals(logger.getLevel())) {
-                    logger.setLevel(li.oldLevel);
-                }
-
-                if (logger.isAdditive() == li.additive) {
-                    logger.setAdditive(li.oldAdditive);
-                }
+            for (final String li : ai.loggers) {
+                final Logger logger = loggerContext.getLogger(li);
 
                 logger.detachAppender(ai.appender);
             }
         }
     }
 
-    private void attachAppender(AppenderInfo ai) {
+    private void attachAppender(final AppenderInfo ai) {
         if (ai == null) {
             return;
         }
-        for (LoggerInfo li : ai.loggers) {
-            Logger logger = loggerContext.getLogger(li.name);
-
-            li.oldLevel = logger.getLevel();
-            li.oldAdditive = logger.isAdditive();
-
-            logger.setLevel(li.level);
-            logger.setAdditive(li.additive);
+        for (final String li : ai.loggers) {
+            final Logger logger = loggerContext.getLogger(li);
 
             logger.addAppender(ai.appender);
         }
@@ -146,7 +129,7 @@ public class AppenderTracker extends Ser
     }
 
     static class AppenderInfo {
-        final List<LoggerInfo> loggers;
+        final List<String> loggers;
 
         final Appender<ILoggingEvent> appender;
 
@@ -156,51 +139,12 @@ public class AppenderTracker extends Ser
             this.appender = appender;
             this.serviceReference = ref;
 
-            List<LoggerInfo> loggers = new ArrayList<LoggerInfo>();
+            List<String> loggers = new ArrayList<String>();
             for (String logger : Util.toList(ref.getProperty(PROP_LOGGER))) {
-                loggers.add(new LoggerInfo(logger));
+                loggers.add(logger);
             }
 
             this.loggers = loggers;
         }
     }
-
-    private static class LoggerInfo {
-        final Level level;
-
-        final String name;
-
-        final boolean additive;
-
-        Level oldLevel;
-
-        boolean oldAdditive;
-
-        public LoggerInfo(String loggerSpec) {
-            String[] parts = loggerSpec.split(":");
-
-            Level level = Level.INFO;
-            if (parts.length >= 2) {
-                level = Level.valueOf(safeTrim(parts[1]));
-            }
-
-            boolean additive = false;
-            if (parts.length >= 3) {
-                additive = Boolean.valueOf(parts[2]);
-            }
-
-            this.level = level;
-            this.name = safeTrim(parts[0]);
-            this.additive = additive;
-        }
-
-    }
-
-    private static String safeTrim(String s) {
-        if (s != null) {
-            return s.trim();
-        }
-        return null;
-    }
-
 }



Mime
View raw message