You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ch...@apache.org on 2015/07/27 11:06:24 UTC

svn commit: r1692840 - in /sling/trunk/bundles/commons/log/src/main: java/org/apache/sling/commons/log/logback/internal/ resources/OSGI-INF/metatype/ resources/res/ui/

Author: chetanm
Date: Mon Jul 27 09:06:24 2015
New Revision: 1692840

URL: http://svn.apache.org/r1692840
Log:
SLING-4839 - Allow to configure logger additivity via OSGi Config UI

Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.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
    sling/trunk/bundles/commons/log/src/main/resources/res/ui/slinglog.js

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java?rev=1692840&r1=1692839&r2=1692840&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java (original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java Mon Jul 27 09:06:24 2015
@@ -162,9 +162,10 @@ public class SlingLogPanel extends HttpS
                 String logger = req.getParameter("logger");
                 String logLevel = req.getParameter("loglevel");
                 String logFile = req.getParameter("logfile");
+                String additive = req.getParameter("logAdditive");
                 String[] loggers = req.getParameterValues("logger");
                 if (null != logger) {
-                    configureLogger(pid, logLevel, loggers, logFile);
+                    configureLogger(pid, logLevel, loggers, logFile, additive);
                 }
             }
         } catch (ConfigurationException e) {
@@ -229,6 +230,7 @@ public class SlingLogPanel extends HttpS
         pw.println("<thead class='ui-widget-header'>");
         pw.println("<tr>");
         pw.println("<th>Log Level</th>");
+        pw.println("<th>Additive</th>");
         pw.println("<th>Log File</th>");
         pw.println("<th>Logger</th>");
         pw.print("<th width=\"20%\">");
@@ -250,6 +252,11 @@ public class SlingLogPanel extends HttpS
             pw.print("\">");
             pw.print(getLevelStr(logConfig));
             pw.println("</span></td>");
+            pw.print("<td><span class=\"logAdditive\" data-currentAdditivity=\"");
+            pw.print(Boolean.toString(logConfig.isAdditive()));
+            pw.print("\">");
+            pw.print(Boolean.toString(logConfig.isAdditive()));
+            pw.println("</span></td>");
             pw.print("<td><span class=\"logFile\">");
             pw.print( XmlUtil.escapeXml(getPath(logConfig.getLogWriterName(), rootPath, shortenPaths)));
             pw.println("</span></td>");
@@ -287,6 +294,7 @@ public class SlingLogPanel extends HttpS
         }
 
         pw.println("\"></span></td>");
+        pw.print("<td><span class=\"logAdditive\" data-currentAdditivity=\"false\"></span></td>");
         pw.print("<td><span id=\"defaultLogfile\" data-defaultlogfile=\"");
         pw.print( XmlUtil.escapeXml(getPath(configManager.getDefaultWriter().getFileName(), rootPath, shortenPaths)));
         pw.println("\" class=\"logFile\"></span></td>");
@@ -645,10 +653,11 @@ public class SlingLogPanel extends HttpS
      * @param logLevel the log level to set
      * @param loggers  list of logger categories to set
      * @param logFile  log file (relative path is ok)
+     * @param additive logger additivity
      * @throws IOException            when an existing configuration couldn't be updated or a configuration couldn't be created.
      * @throws ConfigurationException when mandatory parameters where not specified
      */
-    private void configureLogger(final String pid, final String logLevel, final String[] loggers, final String logFile)
+    private void configureLogger(final String pid, final String logLevel, final String[] loggers, final String logFile, String additive)
             throws IOException, ConfigurationException {
         // try to get the configadmin service reference
         ServiceReference sr = this.bundleContext
@@ -682,6 +691,12 @@ public class SlingLogPanel extends HttpS
                         dict.put(LogConfigManager.LOG_LEVEL, logLevel.toLowerCase());
                         dict.put(LogConfigManager.LOG_LOGGERS, loggers);
                         dict.put(LogConfigManager.LOG_FILE, logFile);
+
+                        if (additive == null){
+                            dict.put(LogConfigManager.LOG_ADDITIV, "false");
+                        } else {
+                            dict.put(LogConfigManager.LOG_ADDITIV, "true");
+                        }
                         config.update(dict);
                     }
                 }

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=1692840&r1=1692839&r2=1692840&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 Jul 27 09:06:24 2015
@@ -85,6 +85,10 @@ log.file.buffered.description = By defau
   If set to true  and if appenders are not closed properly when your application exits, then \
   logging events not yet written to disk may be lost. See http://logback.qos.ch/manual/encoders.html#immediateFlush
 
+log.additiv.name = Additivity
+log.additiv.description = If set to false then logs from these loggers would not be sent \
+   to any appender attached higher in the hierarchy
+
 log.config.maxOldFileCountInDump.name = Max Count of files in dump
 log.config.maxOldFileCountInDump.description = Maximum number of old rolled over files for each \
   active file to be included while generating the dump as part of Status zip support

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=1692840&r1=1692839&r2=1692840&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 Jul 27 09:06:24 2015
@@ -134,6 +134,10 @@
         <metatype:AD id="webconsole.configurationFactory.nameHint"
             type="String"
             default="{org.apache.sling.commons.log.file}: {org.apache.sling.commons.log.level}"/>
+        <metatype:AD id="org.apache.sling.commons.log.additiv"
+             name="%log.additiv.name"
+             description="%log.additiv.description"
+             type="Boolean" />
     </metatype:OCD>
     <metatype:Designate
         pid="org.apache.sling.commons.log.LogManager.factory.config"

Modified: sling/trunk/bundles/commons/log/src/main/resources/res/ui/slinglog.js
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/resources/res/ui/slinglog.js?rev=1692840&r1=1692839&r2=1692840&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/resources/res/ui/slinglog.js (original)
+++ sling/trunk/bundles/commons/log/src/main/resources/res/ui/slinglog.js Mon Jul 27 09:06:24 2015
@@ -19,6 +19,7 @@
  */
 function removeEditor(row) {
     $(row).find(".loggers").toggle();
+	$(row).find(".logAdditive").toggle();
 	$(row).find(".logLevels").toggle();
 	$(row).find(".logFile").toggle();
 	$(row).find(".configureLink").toggle();
@@ -73,6 +74,22 @@ function addLogger(loggersElement, logge
 }
 
 /**
+ * Make checkbox for additive field
+ */
+function addAdditive(row) {
+	var additiveElement = $(row).find(".logAdditive");
+	var currentAdditivity = additiveElement.attr("data-currentAdditivity");
+	if(!currentAdditivity) {
+		// default additivity is false
+		currentAdditivity = "false";
+	}
+
+	var checked = currentAdditivity == "true" ? "checked" : "";
+	additiveElement.after('<input class="editElement ui-state-default" type="checkbox" name="logAdditive" value="true" '+ checked +' />')
+	additiveElement.toggle();
+}
+
+/**
  * Turns the logger elements into inputfields (with controls).
  */
 function addLoggers(row) {
@@ -119,6 +136,7 @@ function configureLogger(button) {
 	row.addClass("currentEditor");
 	// add the editables
     addLogLevelSelect(row);
+    addAdditive(row);
 	addLoggers(row);
     addLogFile(row);
     // add controls