incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1239543 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log: FileRequestLog.java RequestLoggerFilter.java RequestLoggerService.java
Date Thu, 02 Feb 2012 11:19:50 GMT
Author: fmeschbe
Date: Thu Feb  2 11:19:49 2012
New Revision: 1239543

URL: http://svn.apache.org/viewvc?rev=1239543&view=rev
Log:
SLING-2389 Make sure files with relative paths are created within ${sling.home}

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/FileRequestLog.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerFilter.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/FileRequestLog.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/FileRequestLog.java?rev=1239543&r1=1239542&r2=1239543&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/FileRequestLog.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/FileRequestLog.java
Thu Feb  2 11:19:49 2012
@@ -59,17 +59,9 @@ import org.apache.sling.engine.RequestLo
  */
 class FileRequestLog implements RequestLog {
 
-    // The file representing the root directory for relative log file paths
-    private static File relPathRoot;
-
     // The map of shared open files (actually PrintWriter instances)
     private static Map<String, PrintWriter> logFiles = new HashMap<String, PrintWriter>();
 
-    // Initialize class with the root directory for relative log file paths
-    static void init(String relPathRoot) {
-        FileRequestLog.relPathRoot = new File(relPathRoot).getAbsoluteFile();
-    }
-
     // Dispose class by closing all open PrintWeiter instances
     static void dispose() {
         for (final Writer w : logFiles.values()) {
@@ -85,24 +77,13 @@ class FileRequestLog implements RequestL
     // The PrintWriter used by this instance to write the messages
     private PrintWriter output;
 
-    FileRequestLog(String fileName) throws IOException {
-        // ensure the path is absolute
-        File file = new File(fileName);
-        if (!file.isAbsolute()) {
-            file = new File(relPathRoot, fileName);
-        }
-
-        // get back the raw file name
-        fileName = file.getAbsolutePath();
-
+    FileRequestLog(File logFile) throws IOException {
         synchronized (logFiles) {
+            final String fileName = logFile.getAbsolutePath();
             this.output = logFiles.get(fileName);
             if (this.output == null) {
-
-                // ensure location of the log file
-                file.getParentFile().mkdirs();
-
-                FileWriter fw = new FileWriter(file, true);
+                logFile.getParentFile().mkdirs();
+                FileWriter fw = new FileWriter(logFile, true);
                 this.output = new PrintWriter(fw);
                 logFiles.put(fileName, this.output);
             }

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerFilter.java?rev=1239543&r1=1239542&r2=1239543&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerFilter.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerFilter.java
Thu Feb  2 11:19:49 2012
@@ -28,17 +28,14 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.Service;
-import org.osgi.framework.BundleContext;
 
 /**
  * The <code>RequestLogger</code> is a request level filter, which
@@ -102,36 +99,6 @@ public final class RequestLoggerFilter i
     // ---------- SCR Integration ----------------------------------------------
 
     /**
-     * Activates this component by setting up the special request entry and exit
-     * request loggers and the access logger as configured in the context
-     * properties. In addition the <code>FileRequestLog</code> class is
-     * initialized with the value of the <code>sling.home</code> context
-     * property to resolve relative log file names.
-     */
-    @Activate
-    @SuppressWarnings("unused")
-    private void activate(BundleContext bundleContext) {
-
-        // initialize the FileRequestLog with sling.home as the root for
-        // relative log file paths
-        FileRequestLog.init(bundleContext.getProperty("sling.home"));
-
-    }
-
-    /**
-     * Deactivates this component by unbinding and shutting down all loggers
-     * setup during activation and finally dispose off the
-     * <code>FileRequestLog</code> class to make sure all shared writers are
-     * closed.
-     */
-    @Deactivate
-    @SuppressWarnings("unused")
-    private void deactivate() {
-        // hack to ensure all log files are closed
-        FileRequestLog.dispose();
-    }
-
-    /**
      * Binds a <code>RequestLoggerService</code> to be used during request
      * filter.
      *

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=1239543&r1=1239542&r2=1239543&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 Feb  2 11:19:49 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.engine.impl.log;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Map;
 
@@ -137,7 +138,17 @@ public class RequestLoggerService {
             case OUTPUT_TYPE_FILE:
                 // file logging
                 try {
-                    return new FileRequestLog(output);
+                    // ensure the path is absolute
+                    File file = new File(output);
+                    if (!file.isAbsolute()) {
+                        final String home = bundleContext.getProperty("sling.home");
+                        if (home != null) {
+                            file = new File(home, output);
+                        }
+                        file = file.getAbsoluteFile();
+                    }
+
+                    return new FileRequestLog(file);
                 } catch (IOException ioe) {
                     // TODO: log
                 }



Mime
View raw message