You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2022/02/13 10:54:19 UTC

[felix-dev] branch master updated: FELIX-6505 : Allow configuration of log format for request logs

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 885c7b2  FELIX-6505 : Allow configuration of log format for request logs
885c7b2 is described below

commit 885c7b2701a6e6cfcdf70f2ad158e11bde2aa912
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Feb 13 11:54:10 2022 +0100

    FELIX-6505 : Allow configuration of log format for request logs
---
 .../apache/felix/http/jetty/internal/FileRequestLog.java  |  2 +-
 .../org/apache/felix/http/jetty/internal/JettyConfig.java | 15 +++++++++++++++
 .../felix/http/jetty/internal/LogServiceRequestLog.java   | 13 ++++++++-----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
index fbb4854..21ec142 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
@@ -55,7 +55,7 @@ class FileRequestLog {
         writer.setRetainDays(config.getRequestLogFileRetainDays());
         writer.setFilenameDateFormat(config.getRequestLogFilenameDateFormat());
 
-        delegate = new CustomRequestLog(writer, CustomRequestLog.EXTENDED_NCSA_FORMAT);
+        delegate = new CustomRequestLog(writer, config.getRequestLogFileFormat());
         delegate.setIgnorePaths(config.getRequestLogFileIgnorePaths());
     }
 
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
index 3588039..543acd4 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
@@ -30,6 +30,7 @@ import java.util.zip.Deflater;
 
 import org.apache.felix.http.base.internal.HttpConfig;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.eclipse.jetty.server.CustomRequestLog;
 import org.eclipse.jetty.server.handler.gzip.GzipHandler;
 import org.osgi.framework.BundleContext;
 
@@ -183,6 +184,9 @@ public final class JettyConfig
     /** Felix specific property to control the level of the log messages generated by the OSGi Log Service-based request log. Values must correspond to the constants defined in the LogService interface, default is 3 "INFO". */
     public static final String FELIX_HTTP_REQUEST_LOG_OSGI_LEVEL = "org.apache.felix.http.requestlog.osgi.level";
 
+    /** Felix specific property to control the format of the log messages generated by the OSGi Log Service-based request log. */
+    public static final String FELIX_HTTP_REQUEST_LOG_FORMAT = "org.apache.felix.http.requestlog.osgi.format";
+
     /** Felix specific property to enable request logging to a file and provide the path to that file. Default is null meaning that the file log is disabled. */
     public static final String FELIX_HTTP_REQUEST_LOG_FILE_PATH = "org.apache.felix.http.requestlog.file.path";
 
@@ -204,6 +208,9 @@ public final class JettyConfig
     /** Felix specific property to ignore matching paths in the request log file */
     public static final String FELIX_HTTP_REQUEST_LOG_FILE_IGNORE_PATHS = "org.apache.felix.http.requestlog.file.ignorepaths";
 
+    /** Felix specific property to specify the output format for the request log file */
+    public static final String FELIX_HTTP_REQUEST_LOG_FILE_FORMAT = "org.apache.felix.http.requestlog.file.format";
+
     /** Felix specific property to define custom properties for the http runtime service. */
     public static final String FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX = "org.apache.felix.http.runtime.init.";
 
@@ -583,6 +590,10 @@ public final class JettyConfig
         return getIntProperty(FELIX_HTTP_REQUEST_LOG_OSGI_LEVEL, 3); // 3 == LogService.LOG_INFO
     }
 
+    public String getRequestLogOSGiFormat() {
+        return getProperty(FELIX_HTTP_REQUEST_LOG_FORMAT, CustomRequestLog.NCSA_FORMAT);
+    }
+
     public String getRequestLogFilePath() {
         return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_PATH, null);
     }
@@ -603,6 +614,10 @@ public final class JettyConfig
         return getIntProperty(FELIX_HTTP_REQUEST_LOG_FILE_RETAIN_DAYS, 31);
     }
 
+    public String getRequestLogFileFormat() {
+        return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_FORMAT, CustomRequestLog.NCSA_FORMAT);
+    }
+
     public String getRequestLogFilenameDateFormat() {
         return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_FILENAME_DATE_FORMAT, null);
     }
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
index 15078ef..f2bc8a4 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
@@ -21,6 +21,7 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.util.ServiceUtils;
 import org.eclipse.jetty.server.CustomRequestLog;
 import org.eclipse.jetty.server.RequestLog;
 import org.osgi.framework.BundleContext;
@@ -46,7 +47,7 @@ class LogServiceRequestLog extends CustomRequestLog {
                 public void write(String requestEntry) throws IOException {
                     SystemLogger.info(PREFIX.concat(requestEntry));
                 }
-            }, CustomRequestLog.NCSA_FORMAT);
+            },config.getRequestLogOSGiFormat());
         this.serviceName = config.getRequestLogOSGiServiceName();
     }
 
@@ -60,12 +61,14 @@ class LogServiceRequestLog extends CustomRequestLog {
     }
 
     public synchronized void unregister() {
-        try {
-            if (registration != null) {
+        if (registration != null) {
+            try {
                 registration.unregister();
+            } catch ( final IllegalStateException ignore ) {
+                // ignore
+            } finally {
+                registration = null;
             }
-        } finally {
-            registration = null;
         }
     }
 }