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 f33d2909bf FELIX-6610 expose request logging properties through 
metatype (#211)
f33d2909bf is described below

commit f33d2909bfcb28d68254e2f9e6d710faf1d68013
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Jun 5 07:05:47 2023 +0200

    FELIX-6610 expose request logging properties through metatype (#211)
    
    Allow to configure SLF4J logger name through new property
    "org.apache.felix.http.requestlog.osgi.logger.name". Remove unused
    property "org.apache.felix.http.requestlog.osgi.level"
---
 .../jetty/internal/ConfigMetaTypeProvider.java     | 28 ++++++++++++++++++++++
 .../felix/http/jetty/internal/JettyConfig.java     | 12 +++++-----
 .../http/jetty/internal/LogServiceRequestLog.java  | 28 +++++++++++++++-------
 3 files changed, 53 insertions(+), 15 deletions(-)

diff --git 
a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
 
b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
index 4fd5687ffc..9e50ed7673 100644
--- 
a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
+++ 
b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
@@ -22,6 +22,8 @@ import java.io.InputStream;
 import java.util.ArrayList;
 
 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.eclipse.jetty.server.session.HouseKeeper;
 import org.osgi.framework.Bundle;
@@ -455,6 +457,32 @@ class ConfigMetaTypeProvider implements MetaTypeProvider
                 "http/1.1",
                 
bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_ALPN_DEFAULT_PROTOCOL)));
 
+        // most important request logging attributes
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_REQUEST_LOG_FILE_PATH,
+                "Request Log File Path",
+                "The path to the log file which is receiving request log 
entries. If empty no request log file is created",
+                null,
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_REQUEST_LOG_FILE_PATH)));
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_REQUEST_LOG_FILE_FORMAT,
+                "Request Log File Format",
+                "The format of the request log file entries. Only relevant if 
'Request Log File Path' is set. Valid placeholders are described in 
https://www.eclipse.org/jetty/documentation/jetty-11/operations-guide/index.html#og-module-requestlog";,
+                CustomRequestLog.NCSA_FORMAT,
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_REQUEST_LOG_FILE_FORMAT)));
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_REQUEST_LOG_OSGI_ENABLE,
+                "Enable SLF4J Request Logging",
+                "Select to log requests through SLF4J logger with given name 
(on level INFO)",
+                false,
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_REQUEST_LOG_OSGI_ENABLE)));
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_REQUEST_LOG_OSGI_LOGGER_NAME,
+                "SLF4J Request Log Logger Name",
+                "The name of the SLF4J request logger. Only relevant if 
'Enable SLF4J Request Logging' is checked.",
+                SystemLogger.LOGGER.getName(),
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_REQUEST_LOG_OSGI_LOGGER_NAME)));
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_REQUEST_LOG_FORMAT,
+                "SLF4J Request Log Format",
+                "The format of the request log entries. Only relevant if 
'Enable SLF4J Request Logging' is checked. Valid placeholders are described in 
https://www.eclipse.org/jetty/documentation/jetty-11/operations-guide/index.html#og-module-requestlog";,
+                CustomRequestLog.NCSA_FORMAT,
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_REQUEST_LOG_FORMAT)));
         return new ObjectClassDefinition()
         {
 
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 91b561ab0f..ef336ea61c 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
@@ -175,14 +175,14 @@ public final class JettyConfig
     /** Felix specific property to configure a filter for RequestLog services 
*/
     public static final String FELIX_HTTP_REQUEST_LOG_FILTER = 
"org.apache.felix.http.requestlog.filter";
 
-    /** Felix specific property to enable request logging to the OSGi Log 
Service */
+    /** Felix specific property to enable request logging through SLF4J name 
"org.apache.felix.http" (with level INFO) */
     public static final String FELIX_HTTP_REQUEST_LOG_OSGI_ENABLE = 
"org.apache.felix.http.requestlog.osgi.enable";
 
-    /** Felix specific property to specify the published "name" property of 
the OSGi Log Service-base Request Log service. Allows server configs to filter 
on specific log services. */
+    /** Felix specific property to specify the published "name" property of 
the SLF4J Service-based Request Log service. Allows server configs to filter on 
specific log services. */
     public static final String FELIX_HTTP_REQUEST_LOG_OSGI_SERVICE_NAME = 
"org.apache.felix.http.requestlog.osgi.name";
 
-    /** 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 specify the logger name of the SLF4J 
Service-based Request Log service. Log entries are emitted with level INFO. */
+    public static final String FELIX_HTTP_REQUEST_LOG_OSGI_LOGGER_NAME = 
"org.apache.felix.http.requestlog.osgi.logger.name";
 
     /** 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";
@@ -586,8 +586,8 @@ public final class JettyConfig
         return (String) getProperty(FELIX_HTTP_REQUEST_LOG_OSGI_SERVICE_NAME);
     }
 
-    public int getRequestLogOSGiLevel() {
-        return getIntProperty(FELIX_HTTP_REQUEST_LOG_OSGI_LEVEL, 3); // 3 == 
LogService.LOG_INFO
+    public String getRequestLogOsgiSlf4JLoggerName() {
+        return getProperty(FELIX_HTTP_REQUEST_LOG_OSGI_LOGGER_NAME, 
SystemLogger.LOGGER.getName());
     }
 
     public String getRequestLogOSGiFormat() {
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 13bed447a1..6bb9ec43f3 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
@@ -20,14 +20,15 @@ import java.io.IOException;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.eclipse.jetty.server.CustomRequestLog;
 import org.eclipse.jetty.server.RequestLog;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * A RequestLog that logs to the OSGi LogService when present. Not registered 
by default.
+ * A RequestLog that logs via SLF4J when present. Not registered by default.
  */
 class LogServiceRequestLog extends CustomRequestLog {
 
@@ -39,17 +40,26 @@ class LogServiceRequestLog extends CustomRequestLog {
 
     private volatile ServiceRegistration<RequestLog> registration;
 
+    
     LogServiceRequestLog(JettyConfig config) {
-        super(new RequestLog.Writer() {
-
-                @Override
-                public void write(String requestEntry) throws IOException {
-                    SystemLogger.LOGGER.info(PREFIX.concat(requestEntry));
-                }
-            },config.getRequestLogOSGiFormat());
+        super(new 
Slf4JRequestLogWriter(config.getRequestLogOsgiSlf4JLoggerName()), 
config.getRequestLogOSGiFormat());
         this.serviceName = config.getRequestLogOSGiServiceName();
     }
 
+    private static final class Slf4JRequestLogWriter implements 
RequestLog.Writer {
+
+        private final Logger logger;
+
+        public Slf4JRequestLogWriter(String name) {
+            this.logger = LoggerFactory.getLogger(name);
+        }
+
+        @Override
+        public void write(String requestEntry) throws IOException {
+            logger.info(PREFIX.concat(requestEntry));
+        }
+    }
+
     public synchronized void register(BundleContext context) throws 
IllegalStateException {
         if (registration != null) {
             throw new IllegalStateException(getClass().getSimpleName() + " 
already registered");

Reply via email to