You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/04/21 21:13:45 UTC

svn commit: r1740387 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log: RequestLogger.java RequestLoggerService.java

Author: olli
Date: Thu Apr 21 19:13:45 2016
New Revision: 1740387

URL: http://svn.apache.org/viewvc?rev=1740387&view=rev
Log:
SLING-5678 RequestLogger and RequestLoggerService should use PropertiesUtil to parse their configs

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLogger.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerService.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLogger.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLogger.java?rev=1740387&r1=1740386&r2=1740387&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLogger.java (original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLogger.java Thu Apr 21 19:13:45 2016
@@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyOption;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
@@ -99,23 +100,20 @@ public class RequestLogger {
 
         // prepare the request loggers if a name is configured and the
         // request loggers are enabled
-        Object requestLogName = props.get(PROP_REQUEST_LOG_OUTPUT);
-        Object requestLogEnabled = props.get(PROP_REQUEST_LOG_ENABLED);
-        if (requestLogName != null && requestLogEnabled instanceof Boolean
-            && ((Boolean) requestLogEnabled).booleanValue()) {
-            Object requestLogType = props.get(PROP_REQUEST_LOG_OUTPUT_TYPE);
-            createRequestLoggerService(services, bundleContext, true, REQUEST_LOG_ENTRY_FORMAT, requestLogName,
-                requestLogType);
-            createRequestLoggerService(services, bundleContext, false, REQUEST_LOG_EXIT_FORMAT, requestLogName,
-                requestLogType);
+        final String requestLogName = PropertiesUtil.toString(props.get(PROP_REQUEST_LOG_OUTPUT), null);
+        final boolean requestLogEnabled = PropertiesUtil.toBoolean(props.get(PROP_REQUEST_LOG_ENABLED), false);
+        if (requestLogName != null && requestLogEnabled) {
+            final int requestLogType = PropertiesUtil.toInteger(props.get(PROP_REQUEST_LOG_OUTPUT_TYPE), 0);
+            createRequestLoggerService(services, bundleContext, true, REQUEST_LOG_ENTRY_FORMAT, requestLogName, requestLogType);
+            createRequestLoggerService(services, bundleContext, false, REQUEST_LOG_EXIT_FORMAT, requestLogName, requestLogType);
         }
 
         // prepare the access logger if a name is configured and the
         // access logger is enabled
-        Object accessLogName = props.get(PROP_ACCESS_LOG_OUTPUT);
-        Object accessLogEnabled = props.get(PROP_ACCESS_LOG_ENABLED);
-        if (accessLogName != null && accessLogEnabled instanceof Boolean && ((Boolean) accessLogEnabled).booleanValue()) {
-            Object accessLogType = props.get(PROP_ACCESS_LOG_OUTPUT_TYPE);
+        final String accessLogName = PropertiesUtil.toString(props.get(PROP_ACCESS_LOG_OUTPUT), null);
+        final boolean accessLogEnabled = PropertiesUtil.toBoolean(props.get(PROP_ACCESS_LOG_ENABLED), false);
+        if (accessLogName != null && accessLogEnabled) {
+            final int accessLogType = PropertiesUtil.toInteger(props.get(PROP_ACCESS_LOG_OUTPUT_TYPE), 0);
             createRequestLoggerService(services, bundleContext, false, ACCESS_LOG_FORMAT, accessLogName, accessLogType);
         }
     }
@@ -129,8 +127,7 @@ public class RequestLogger {
         services.clear();
     }
 
-    private static void createRequestLoggerService(Map<ServiceRegistration, RequestLoggerService> services,
-            BundleContext bundleContext, boolean onEntry, Object format, Object output, Object outputType) {
+    private static void createRequestLoggerService(Map<ServiceRegistration, RequestLoggerService> services, BundleContext bundleContext, boolean onEntry, Object format, String output, Object outputType) {
         final Hashtable<String, Object> config = new Hashtable<String, Object>();
         config.put(RequestLoggerService.PARAM_ON_ENTRY, onEntry ? Boolean.TRUE : Boolean.FALSE);
         config.put(RequestLoggerService.PARAM_FORMAT, format);

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerService.java?rev=1740387&r1=1740386&r2=1740387&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerService.java (original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerService.java Thu Apr 21 19:13:45 2016
@@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.engine.RequestLog;
 import org.osgi.framework.BundleContext;
 
@@ -90,23 +91,19 @@ public class RequestLoggerService {
     @Activate
     void setup(BundleContext bundleContext, Map<String, Object> configuration) {
         // whether to log on request entry or request exit
-        Object onEntryObject = configuration.get(PARAM_ON_ENTRY);
-        this.onEntry = (onEntryObject instanceof Boolean) ? ((Boolean) onEntryObject).booleanValue() : false;
+        this.onEntry = PropertiesUtil.toBoolean(configuration.get(PARAM_ON_ENTRY), false);
 
         // shared or private CustomLogFormat
-        Object format = configuration.get(PARAM_FORMAT);
+        final String format = PropertiesUtil.toString(configuration.get(PARAM_FORMAT), null);
         if (format != null) {
-            this.logFormat = new CustomLogFormat(format.toString());
+            this.logFormat = new CustomLogFormat(format);
         }
 
         // where to log to
-        Object output = configuration.get(PARAM_OUTPUT);
+        final String output = PropertiesUtil.toString(configuration.get(PARAM_OUTPUT), null);
         if (output != null) {
-            Object outputTypeObject = configuration.get(PARAM_OUTPUT_TYPE);
-            int outputType = (outputTypeObject instanceof Number)
-                    ? ((Number) outputTypeObject).intValue()
-                    : OUTPUT_TYPE_LOGGER;
-            this.log = this.getLog(bundleContext, output.toString(), outputType);
+            final int outputType = PropertiesUtil.toInteger(configuration.get(PARAM_OUTPUT_TYPE), OUTPUT_TYPE_LOGGER);
+            this.log = this.getLog(bundleContext, output, outputType);
         }
     }