incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1571318 - in /sling/trunk/bundles/commons/log/src/main: java/org/apache/sling/commons/log/logback/internal/ java/org/apache/sling/commons/log/logback/internal/util/ resources/OSGI-INF/metatype/
Date Mon, 24 Feb 2014 15:22:24 GMT
Author: chetanm
Date: Mon Feb 24 15:22:23 2014
New Revision: 1571318

URL: http://svn.apache.org/r1571318
Log:
SLING-3411 - Enable configuring the maxCallerDataDepth in Logback LoggerContext

-- Added config for specifying the maxCallerDepth
-- Updated doc around Logging pattern. It now refers to Logback config docs

Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/Util.java
    sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.xml

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java?rev=1571318&r1=1571317&r2=1571318&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
Mon Feb 24 15:22:23 2014
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
+import ch.qos.logback.classic.ClassicConstants;
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
@@ -69,6 +70,8 @@ public class LogConfigManager implements
 
     public static final String LOG_PACKAGING_DATA = "org.apache.sling.commons.log.packagingDataEnabled";
 
+    public static final String LOG_MAX_CLALLER_DEPTH = "org.apache.sling.commons.log.maxCallerDataDepth";
+
     public static final String LOG_LEVEL_DEFAULT = "INFO";
 
     public static final int LOG_FILE_NUMBER_DEFAULT = 5;
@@ -121,6 +124,8 @@ public class LogConfigManager implements
 
     private boolean packagingDataEnabled;
 
+    private int maxCallerDataDepth;
+
     /**
      * Logs a message an optional stack trace to error output. This method is
      * used by the logging system in case of errors writing to the correct
@@ -564,6 +569,10 @@ public class LogConfigManager implements
         return packagingDataEnabled;
     }
 
+    public int getMaxCallerDataDepth() {
+        return maxCallerDataDepth;
+    }
+
     // ---------- ManagedService interface -------------------------------------
 
     private Dictionary<String, String> getBundleConfiguration(BundleContext bundleContext)
{
@@ -614,6 +623,9 @@ public class LogConfigManager implements
             //Defaults to false i.e. disabled in OSGi env
             packagingDataEnabled = false;
         }
+
+        maxCallerDataDepth = Util.toInteger(configuration.get(LOG_MAX_CLALLER_DEPTH),
+                ClassicConstants.DEFAULT_MAX_CALLEDER_DATA_DEPTH);
     }
 
     // ---------- Internal helpers ---------------------------------------------

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java?rev=1571318&r1=1571317&r2=1571318&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
Mon Feb 24 15:22:23 2014
@@ -462,6 +462,7 @@ public class LogbackManager extends Logg
                 + " listeners");
 
             context.setPackagingDataEnabled(logConfigManager.isPackagingDataEnabled());
+            context.setMaxCallerDataDepth(logConfigManager.getMaxCallerDataDepth());
 
             // Attach a console appender to handle logging untill we configure
             // one. This would be removed in RootLoggerListener.reset

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/Util.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/Util.java?rev=1571318&r1=1571317&r2=1571318&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/Util.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/Util.java
Mon Feb 24 15:22:23 2014
@@ -76,4 +76,51 @@ public class Util {
         }
     }
 
+    //-------------Taken from org.apache.sling.commons.osgi.PropertiesUtil
+
+    /**
+     * Returns the parameter as an integer or the
+     * <code>defaultValue</code> if the parameter is <code>null</code>
or if
+     * the parameter is not an <code>Integer</code> and cannot be converted to
+     * an <code>Integer</code> from the parameter's string value.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default integer value
+     */
+    public static int toInteger(Object propValue, int defaultValue) {
+        propValue = toObject(propValue);
+        if (propValue instanceof Integer) {
+            return (Integer) propValue;
+        } else if (propValue != null) {
+            try {
+                return Integer.valueOf(String.valueOf(propValue));
+            } catch (NumberFormatException nfe) {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a single value. If the
+     * parameter is neither an array nor a <code>java.util.Collection</code>
the
+     * parameter is returned unmodified. If the parameter is a non-empty array,
+     * the first array element is returned. If the property is a non-empty
+     * <code>java.util.Collection</code>, the first collection element is returned.
+     * Otherwise <code>null</code> is returned.
+     * @param propValue the parameter to convert.
+     */
+    public static Object toObject(Object propValue) {
+        if (propValue == null) {
+            return null;
+        } else if (propValue.getClass().isArray()) {
+            Object[] prop = (Object[]) propValue;
+            return prop.length > 0 ? prop[0] : null;
+        } else if (propValue instanceof Collection<?>) {
+            Collection<?> prop = (Collection<?>) propValue;
+            return prop.isEmpty() ? null : prop.iterator().next();
+        } else {
+            return propValue;
+        }
+    }
 }

Modified: sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1571318&r1=1571317&r2=1571318&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.properties
Mon Feb 24 15:22:23 2014
@@ -50,12 +50,8 @@ log.file.size.description = Controls the
   pattern. The default is "'.'yyyy-MM-dd" (daily log rotation).
 
 log.pattern.name = Message Pattern
-log.pattern.description = Message Pattern for formatting the log messages. \
- This is a java.text.MessageFormat pattern supporting up to six arguments: \
- {0} The timestamp of type java.util.Date, {1} the log marker, {2} the name \
- of the current thread, {3} the name of the logger, {4} the debug level and \
- {5} the actual debug message. If the log call includes a Throwable, the \
- stacktrace is just appended to the message.
+log.pattern.description = Message Pattern for formatting the log messages. For \
+  complete details refer to http://logback.qos.ch/manual/layouts.html#ClassicPatternLayout
  
 log.factory.writer.name = Apache Sling Logging Writer Configuration
 log.factory.writer.description = Configure a Logger Writer for Sling Logging. \
@@ -77,4 +73,8 @@ log.loggers.description = The logger nam
 log.config.packagingData.name = Packaging Data
 log.config.packagingData.description = Include the packaging data which provide \
   details about jar name and version of jar from which the class is loaded as part \
-  of stacktrace. See http://logback.qos.ch/reasonsToSwitch.html#packagingData
\ No newline at end of file
+  of stacktrace. See http://logback.qos.ch/reasonsToSwitch.html#packagingData
+
+log.config.maxCallerDataDepth.name = Max Caller Depth
+log.config.maxCallerDataDepth.description = The stack data depth computed during caller data
\
+  extraction. See http://logback.qos.ch/manual/layouts.html#caller
\ No newline at end of file

Modified: sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.xml?rev=1571318&r1=1571317&r2=1571318&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.xml (original)
+++ sling/trunk/bundles/commons/log/src/main/resources/OSGI-INF/metatype/metatype.xml Mon
Feb 24 15:22:23 2014
@@ -44,7 +44,7 @@
             description="%log.file.size.description" />
         <metatype:AD id="org.apache.sling.commons.log.pattern"
             type="String"
-            default="{0\,date\,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"
+            default="%d{dd.MM.yyyy HH:mm:ss.SSS} *%level* [%thread] %logger %msg%n"
             name="%log.pattern.name"
             description="%log.pattern.description" />
         <metatype:AD id="org.apache.sling.commons.log.configurationFile"
@@ -55,6 +55,11 @@
              type="Boolean"
              name="%log.config.packagingData.name"
              description="%log.config.packagingData.description" />
+        <metatype:AD id="org.apache.sling.commons.log.maxCallerDataDepth"
+             type="Integer"
+             default="7"
+             name="%log.config.maxCallerDataDepth.name"
+             description="%log.config.maxCallerDataDepth.description" />
     </metatype:OCD>
     <metatype:Designate pid="org.apache.sling.commons.log.LogManager">
         <metatype:Object



Mime
View raw message