incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r901096 - in /sling/trunk/bundles/commons/log: ./ src/main/java/org/apache/sling/commons/log/internal/ src/main/java/org/apache/sling/commons/log/internal/slf4j/ src/main/resources/META-INF/
Date Wed, 20 Jan 2010 08:05:39 GMT
Author: cziegeler
Date: Wed Jan 20 08:04:49 2010
New Revision: 901096

URL: http://svn.apache.org/viewvc?rev=901096&view=rev
Log:
SLING-1299 : Provide a web console configuration printer for the log files

Added:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
  (with props)
Modified:
    sling/trunk/bundles/commons/log/NOTICE
    sling/trunk/bundles/commons/log/pom.xml
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
    sling/trunk/bundles/commons/log/src/main/resources/META-INF/NOTICE

Modified: sling/trunk/bundles/commons/log/NOTICE
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/NOTICE?rev=901096&r1=901095&r2=901096&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/NOTICE (original)
+++ sling/trunk/bundles/commons/log/NOTICE Wed Jan 20 08:04:49 2010
@@ -1,5 +1,5 @@
 Apache Sling OSGi LogService Implementation
-Copyright 2008-2009 The Apache Software Foundation
+Copyright 2008-2010 The Apache Software Foundation
 
 Apache Sling is based on source code originally developed 
 by Day Software (http://www.day.com/).

Modified: sling/trunk/bundles/commons/log/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/pom.xml?rev=901096&r1=901095&r2=901096&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/pom.xml (original)
+++ sling/trunk/bundles/commons/log/pom.xml Wed Jan 20 08:04:49 2010
@@ -73,6 +73,7 @@
                         </Private-Package>
                         <Import-Package>
                             javax.servlet.*;resolution:=optional,
+                            org.apache.felix.webconsole;resolution:=optional,
                             org.osgi.framework;version=1.3,
                             *
                         </Import-Package>
@@ -137,6 +138,13 @@
             <artifactId>servlet-api</artifactId>
         </dependency>
         
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <version>2.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        
         <!-- testing -->
         <dependency>
             <groupId>junit</groupId>

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java?rev=901096&r1=901095&r2=901096&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
Wed Jan 20 08:04:49 2010
@@ -20,6 +20,7 @@
 import java.util.Hashtable;
 
 import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.apache.sling.commons.log.internal.slf4j.SlingConfigurationPrinter;
 import org.apache.sling.commons.log.internal.slf4j.SlingLogPanel;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -123,6 +124,12 @@
             SlingLogPanel.registerPanel(context);
         } catch (Throwable ignore) {
         }
+        // setup the web console configuration printer. This may fail loading
+        // the class if the web console API is not wired
+        try {
+            SlingConfigurationPrinter.registerPrinter(context);
+        } catch (Throwable ignore) {
+        }
     }
 
     void shutdown() {
@@ -133,6 +140,11 @@
              SlingLogPanel.unregisterPanel();
         } catch (Throwable ignore) {
         }
+        // tear down the web console configuration printer (if created at all).
+        try {
+            SlingConfigurationPrinter.unregisterPrinter();
+        } catch (Throwable ignore) {
+        }
 
         if (loggingConfigurable != null) {
             loggingConfigurable.unregister();

Added: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java?rev=901096&view=auto
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
(added)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
Wed Jan 20 08:04:49 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.log.internal.slf4j;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The <code>SlingConfigurationPrinter</code> is an Apache Felix
+ * Web Console plugin to display the currently configured log
+ * files.
+ */
+public class SlingConfigurationPrinter implements ConfigurationPrinter {
+
+    /** The registration. */
+    private static ServiceRegistration registration;
+
+    public static void registerPrinter(BundleContext ctx) {
+        if (registration == null) {
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+
+            SlingConfigurationPrinter printer = new SlingConfigurationPrinter();
+            registration = ctx.registerService(ConfigurationPrinter.class.getName(),
+                    printer, props);
+        }
+    }
+
+    public static void unregisterPrinter() {
+        if (registration != null) {
+            registration.unregister();
+            registration = null;
+        }
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Log Files";
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter printWriter) {
+        final LogConfigManager logConfigManager = LogConfigManager.getInstance();
+        Iterator<SlingLoggerWriter> writers = logConfigManager.getSlingLoggerWriters();
+        while (writers.hasNext()) {
+            final SlingLoggerWriter writer = writers.next();
+            final File file = writer.getFile();
+            if ( file != null ) {
+                printWriter.print("Log file ");
+                printWriter.println(getPath(writer));
+                printWriter.println("--------------------------------------------------");
+                FileReader fr = null;
+                try {
+                    fr = new FileReader(file);
+                    final char[] buffer = new char[512];
+                    int len;
+                    while ((len = fr.read(buffer)) != -1 ) {
+                        printWriter.write(buffer, 0, len);
+                    }
+                } catch (IOException ignore) {
+                    // we just ignore this
+                    if ( fr != null ) {
+                        try {
+                            fr.close();
+                            fr = null;
+                        } catch (IOException ignoreCloseException) {}
+                    }
+                }
+                printWriter.println();
+            }
+        }
+    }
+
+    private static String getPath(SlingLoggerWriter writer) {
+        final String path = writer.getPath();
+        return (path != null) ? path : "[stdout]";
+    }
+}

Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java?rev=901096&r1=901095&r2=901096&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
Wed Jan 20 08:04:49 2010
@@ -189,6 +189,10 @@
         return fileRotator;
     }
 
+    File getFile() {
+        return file;
+    }
+
     // ---------- Writer Overwrite ---------------------------------------------
 
     @Override

Modified: sling/trunk/bundles/commons/log/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/resources/META-INF/NOTICE?rev=901096&r1=901095&r2=901096&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/resources/META-INF/NOTICE (original)
+++ sling/trunk/bundles/commons/log/src/main/resources/META-INF/NOTICE Wed Jan 20 08:04:49
2010
@@ -1,5 +1,5 @@
 Apache Sling OSGi LogService Implementation
-Copyright 2008-2009 The Apache Software Foundation
+Copyright 2008-2010 The Apache Software Foundation
 
 Apache Sling is based on source code originally developed 
 by Day Software (http://www.day.com/).



Mime
View raw message