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/11/16 09:01:00 UTC
[felix-dev] branch master updated: FELIX-6582 : Switch to slf4j logging
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 568cdb3220 FELIX-6582 : Switch to slf4j logging
568cdb3220 is described below
commit 568cdb32207600f8065dd0e3351f73d607809432
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Nov 16 10:00:53 2022 +0100
FELIX-6582 : Switch to slf4j logging
---
http/base/pom.xml | 12 +-
.../http/base/internal/AbstractActivator.java | 16 +--
.../felix/http/base/internal/EventDispatcher.java | 6 +-
.../http/base/internal/dispatch/Dispatcher.java | 2 +-
.../internal/dispatch/ServletResponseWrapper.java | 4 +-
.../http/base/internal/handler/FilterHandler.java | 10 +-
.../base/internal/handler/PreprocessorHandler.java | 12 +-
.../http/base/internal/handler/ServletHandler.java | 9 +-
.../http/base/internal/logger/ConsoleLogger.java | 81 -----------
.../http/base/internal/logger/InternalLogger.java | 26 ----
.../http/base/internal/logger/JDK14Logger.java | 74 ----------
.../internal/logger/LogServiceEnabledLogger.java | 158 ---------------------
.../base/internal/logger/LogServiceSupport.java | 40 ------
.../base/internal/logger/R6LogServiceLogger.java | 46 ------
.../http/base/internal/logger/SystemLogger.java | 110 +++-----------
.../internal/registry/EventListenerRegistry.java | 32 ++---
.../registry/PerContextHandlerRegistry.java | 6 +-
.../http/base/internal/runtime/AbstractInfo.java | 4 +-
.../base/internal/runtime/dto/FailedDTOHolder.java | 2 +-
.../internal/service/PerBundleHttpServiceImpl.java | 2 +-
.../base/internal/service/ServletContextImpl.java | 6 +-
.../internal/whiteboard/FailureStateHandler.java | 14 +-
.../whiteboard/SharedServletContextImpl.java | 6 +-
.../internal/whiteboard/WhiteboardManager.java | 7 +-
http/bridge/pom.xml | 7 +-
.../http/bridge/internal/BridgeActivator.java | 2 +-
http/jetty/pom.xml | 4 +-
.../jetty/internal/ConnectorFactoryTracker.java | 4 +-
.../felix/http/jetty/internal/FileRequestLog.java | 6 +-
.../felix/http/jetty/internal/JettyConfig.java | 2 +-
.../jetty/internal/JettyManagedServiceFactory.java | 4 +-
.../felix/http/jetty/internal/JettyService.java | 20 +--
.../http/jetty/internal/LogServiceRequestLog.java | 2 +-
.../http/jetty/internal/RequestLogTracker.java | 8 +-
.../http/jetty/internal/RequestLogTrackerTest.java | 1 +
35 files changed, 116 insertions(+), 629 deletions(-)
diff --git a/http/base/pom.xml b/http/base/pom.xml
index 12ccefb8d7..fa09b635c5 100644
--- a/http/base/pom.xml
+++ b/http/base/pom.xml
@@ -43,6 +43,12 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.36</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -79,12 +85,6 @@
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.log</artifactId>
- <version>1.3.0</version>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.useradmin</artifactId>
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
index f7a062b1e9..38cb1c43b3 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
@@ -16,35 +16,29 @@
*/
package org.apache.felix.http.base.internal;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public abstract class AbstractActivator
- implements BundleActivator
-{
+ implements BundleActivator {
+
private volatile BundleContext context;
- protected final BundleContext getBundleContext()
- {
+ protected final BundleContext getBundleContext() {
return this.context;
}
@Override
public final void start(final BundleContext context)
- throws Exception
- {
+ throws Exception {
this.context = context;
- SystemLogger.init(context);
doStart();
}
@Override
public final void stop(final BundleContext context)
- throws Exception
- {
+ throws Exception {
doStop();
- SystemLogger.destroy();
}
protected abstract void doStart()
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
index 1525251212..7ea85c014e 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
@@ -26,11 +26,7 @@ import jakarta.servlet.http.HttpSessionListener;
* The <code>EventDispatcher</code> dispatches events sent from the servlet
* container (embedded Jetty or container in which the framework is running
* in bridged mode) to any {@link HttpSessionListener} or
- * {@link HttpSessionListener} services.
- *
- * TODO - only HttpSessionIdListener and HttpSessionListener should be
- * required; HttpSessionListener only for getting notified of
- * terminated session.
+ * {@link HttpSessionIdListener} services.
*/
public class EventDispatcher implements HttpSessionListener, HttpSessionIdListener
{
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
index cdbb027e09..786857ee4e 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
@@ -158,7 +158,7 @@ public final class Dispatcher
if ( e instanceof ServletExceptionWrapper ) {
e = ((ServletExceptionWrapper)e).getException();
}
- SystemLogger.error("Exception while processing request to " + requestURI, e);
+ SystemLogger.LOGGER.error("Exception while processing request to " + requestURI, e);
req.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
req.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass().getName());
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java
index c0e8dbefec..eff08af7b1 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java
@@ -32,8 +32,6 @@ import jakarta.servlet.http.HttpServletResponseWrapper;
import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
final class ServletResponseWrapper extends HttpServletResponseWrapper
{
@@ -101,7 +99,7 @@ final class ServletResponseWrapper extends HttpServletResponseWrapper
final String servletPath = null;
final String pathInfo = request.getRequestURI();
- final String queryString = null; // XXX
+ final String queryString = null;
final RequestInfo requestInfo = new RequestInfo(servletPath, pathInfo, queryString, pathInfo,
request.getHttpServletMapping().getServletName(),
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
index ddc917b4af..18dd13154f 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
@@ -125,9 +125,8 @@ public class FilterHandler implements Comparable<FilterHandler>
}
catch (final Exception e)
{
- SystemLogger.error(this.getFilterInfo().getServiceReference(),
- "Error during calling init() on filter " + this.filterInfo.getClassName(this.filter),
- e);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getFilterInfo().getServiceReference(),
+ "Error during calling init() on filter ".concat(this.filterInfo.getClassName(this.filter))), e);
getFilterInfo().ungetService(this.bundleContext, this.filter);
return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
}
@@ -167,9 +166,8 @@ public class FilterHandler implements Comparable<FilterHandler>
catch ( final Exception ignore )
{
// we ignore this
- SystemLogger.error(this.getFilterInfo().getServiceReference(),
- "Error during calling destroy() on filter " + this.getFilterInfo().getClassName(f),
- ignore);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getFilterInfo().getServiceReference(),
+ "Error during calling destroy() on filter ".concat(this.getFilterInfo().getClassName(f))), ignore);
}
getFilterInfo().ungetService(this.bundleContext, f);
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java
index 912692111b..ae30fdadaf 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java
@@ -22,7 +22,6 @@ import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.PreprocessorInfo;
import org.jetbrains.annotations.NotNull;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.servlet.runtime.dto.DTOConstants;
import org.osgi.service.servlet.whiteboard.Preprocessor;
@@ -73,7 +72,6 @@ public class PreprocessorHandler implements Comparable<PreprocessorHandler>
public int init()
{
- final ServiceReference<Preprocessor> serviceReference = this.info.getServiceReference();
this.preprocessor = this.getPreprocessorInfo().getService(this.bundleContext);
if (this.preprocessor == null)
@@ -89,9 +87,8 @@ public class PreprocessorHandler implements Comparable<PreprocessorHandler>
}
catch (final Exception e)
{
- SystemLogger.error(this.getPreprocessorInfo().getServiceReference(),
- "Error during calling init() on preprocessor " + this.info.getClassName(this.preprocessor),
- e);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getPreprocessorInfo().getServiceReference(),
+ "Error during calling init() on preprocessor ".concat(this.info.getClassName(this.preprocessor))), e);
this.getPreprocessorInfo().ungetService(this.bundleContext, this.preprocessor);
this.preprocessor = null;
@@ -116,9 +113,8 @@ public class PreprocessorHandler implements Comparable<PreprocessorHandler>
catch ( final Exception ignore )
{
// we ignore this
- SystemLogger.error(this.getPreprocessorInfo().getServiceReference(),
- "Error during calling destroy() on preprocessor " + this.info.getClassName(this.preprocessor),
- ignore);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getPreprocessorInfo().getServiceReference(),
+ "Error during calling destroy() on preprocessor ".concat(this.info.getClassName(this.preprocessor))), ignore);
}
this.getPreprocessorInfo().ungetService(this.bundleContext, this.preprocessor);
this.preprocessor = null;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
index e378783ae8..658e2806b0 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
@@ -178,8 +178,8 @@ public abstract class ServletHandler implements Comparable<ServletHandler>
}
catch (final Exception e)
{
- SystemLogger.error(this.getServletInfo().getServiceReference(),
- "Error during calling init() on servlet " + this.servletInfo.getClassName(this.servlet),
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getServletInfo().getServiceReference(),
+ "Error during calling init() on servlet ".concat(this.servletInfo.getClassName(this.servlet))),
e);
return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
}
@@ -205,9 +205,8 @@ public abstract class ServletHandler implements Comparable<ServletHandler>
catch ( final Exception ignore )
{
// we ignore this
- SystemLogger.error(this.getServletInfo().getServiceReference(),
- "Error during calling destroy() on servlet " + this.servletInfo.getClassName(this.servlet),
- ignore);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getServletInfo().getServiceReference(),
+ "Error during calling destroy() on servlet ".concat(this.servletInfo.getClassName(this.servlet))), ignore);
}
servlet = null;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java
deleted file mode 100644
index a669cec295..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-import java.io.PrintStream;
-
-import org.osgi.service.log.LogService;
-
-public final class ConsoleLogger implements InternalLogger
-{
- @Override
- public void log(final int level, final String message, final Throwable ex)
- {
- if ( isLogEnabled(level) )
- {
- // output depending on level
- final PrintStream out = ( level == LogService.LOG_ERROR )? System.err: System.out;
-
- // level as a string
- final StringBuilder buf = new StringBuilder();
- switch (level)
- {
- case ( LogService.LOG_DEBUG ):
- buf.append( "[DEBUG] " );
- break;
- case ( LogService.LOG_INFO ):
- buf.append( "[INFO] " );
- break;
- case ( LogService.LOG_WARNING ):
- buf.append( "[WARN] " );
- break;
- case ( LogService.LOG_ERROR ):
- buf.append( "[ERROR] " );
- break;
- default:
- buf.append( "UNK : " );
- break;
- }
-
- buf.append(message);
-
- final String msg = buf.toString();
-
- if ( ex == null )
- {
- out.println(msg);
- }
- else
- {
- // keep the message and the stacktrace together
- synchronized ( out )
- {
- out.println( msg );
- ex.printStackTrace( out );
- }
- }
- }
- }
-
- @Override
- public boolean isLogEnabled(final int level)
- {
- return true;
- }
-}
\ No newline at end of file
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/InternalLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/InternalLogger.java
deleted file mode 100644
index d3fc9aa131..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/InternalLogger.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-interface InternalLogger {
-
- void log(int level, String message, Throwable exception);
-
- boolean isLogEnabled(int level);
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/JDK14Logger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/JDK14Logger.java
deleted file mode 100644
index 8e7f9079f7..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/JDK14Logger.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.service.log.LogService;
-
-/**
- * Logger based on Java Logging API.
- */
-public final class JDK14Logger implements InternalLogger
-{
- private final Logger logger = Logger.getLogger("org.apache.felix.http");
-
- private Level getLevel(final int level)
- {
- Level logLevel;
- switch (level)
- {
- case LogService.LOG_DEBUG:
- logLevel = Level.FINE;
- break;
- case LogService.LOG_INFO:
- logLevel = Level.INFO;
- break;
- case LogService.LOG_WARNING:
- logLevel = Level.WARNING;
- break;
- case LogService.LOG_ERROR:
- logLevel = Level.SEVERE;
- break;
- default: logLevel = Level.FINE;
- }
- return logLevel;
- }
-
- @Override
- public boolean isLogEnabled(final int level) {
- return this.logger.isLoggable(getLevel(level));
- }
-
- @Override
- public void log(final int level, final String message, final Throwable exception)
- {
- final Level logLevel = getLevel(level);
-
- if (exception != null)
- {
- this.logger.log(logLevel, message, exception);
- }
- else
- {
- this.logger.log(logLevel, message);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceEnabledLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceEnabledLogger.java
deleted file mode 100644
index dc74510b95..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceEnabledLogger.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-import org.apache.felix.http.base.internal.util.ServiceUtils;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-/**
- * This abstract class adds support for using a LogService
- */
-public class LogServiceEnabledLogger
-{
- // name of the LogService class (this is a string to not create a reference to the class)
- // With R7, LogService is deprecated but extends the newer LoggerFactory
- private static final String LOGSERVICE_CLASS = "org.osgi.service.log.LogService";
-
- private static final String JUL_LOGGER = "org.apache.felix.http.log.jul";
-
- // the log service to log messages to
- protected final ServiceTracker<Object, Object> logServiceTracker;
-
- private volatile InternalLogger currentLogger;
-
- protected volatile int trackingCount = -2;
-
- private final InternalLogger defaultLogger;
-
- public LogServiceEnabledLogger(final BundleContext bundleContext)
- {
- Object julLogOpt = bundleContext.getProperty(JUL_LOGGER);
- if ( julLogOpt == null ) {
- julLogOpt = System.getProperty(JUL_LOGGER);
- }
- if ( julLogOpt != null ) {
- this.defaultLogger = new JDK14Logger();
- } else {
- this.defaultLogger = new ConsoleLogger();
- }
-
- // Start a tracker for the log service
- // we only track a single log service which in reality should be enough
- logServiceTracker = new ServiceTracker<>( bundleContext, LOGSERVICE_CLASS, new ServiceTrackerCustomizer<Object, Object>()
- {
- private volatile boolean hasService = false;
-
- @Override
- public Object addingService(final ServiceReference<Object> reference)
- {
- if ( !hasService )
- {
- final Object logService = ServiceUtils.safeGetService(bundleContext, reference);
- if ( logService != null )
- {
- hasService = true;
- final LogServiceSupport lsl = new LogServiceSupport(logService);
- return lsl;
- }
- }
- return null;
- }
-
- @Override
- public void modifiedService(final ServiceReference<Object> reference, final Object service)
- {
- // nothing to do
- }
-
- @Override
- public void removedService(final ServiceReference<Object> reference, final Object service)
- {
- hasService = false;
- ServiceUtils.safeUngetService(bundleContext, reference);
- }
- } );
- logServiceTracker.open();
- }
-
- /**
- * Close the logger
- */
- public void close()
- {
- // stop the tracker
- logServiceTracker.close();
- }
-
- /**
- * Returns {@code true} if logging for the given level is enabled.
- */
- public boolean isLogEnabled(final int level)
- {
- return getLogger().isLogEnabled(level);
- }
-
- /**
- * Method to actually emit the log message. If the LogService is available,
- * the message will be logged through the LogService. Otherwise the message
- * is logged to stdout (or stderr in case of LOG_ERROR level messages),
- *
- * @param level The log level of the messages. This corresponds to the log
- * levels defined by the OSGi LogService.
- * @param message The message to print
- * @param ex The <code>Throwable</code> causing the message to be logged.
- */
- public void log(final int level, final String message, final Throwable ex)
- {
- if ( isLogEnabled( level ) )
- {
- getLogger().log(level, message, ex);
- }
- }
-
- /**
- * Get the internal logger
- * @return The internal logger
- */
- InternalLogger getLogger()
- {
- if ( this.trackingCount < this.logServiceTracker.getTrackingCount() )
- {
- final Object logServiceSupport = this.logServiceTracker.getService();
- if ( logServiceSupport == null )
- {
- this.currentLogger = this.getDefaultLogger();
- }
- else
- {
- this.currentLogger = ((LogServiceSupport)logServiceSupport).getLogger();
- }
- this.trackingCount = this.logServiceTracker.getTrackingCount();
- }
- return currentLogger;
- }
-
- InternalLogger getDefaultLogger()
- {
- return this.defaultLogger;
- }
-}
\ No newline at end of file
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceSupport.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceSupport.java
deleted file mode 100644
index a368185166..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceSupport.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-import org.osgi.service.log.LogService;
-
-/**
- * This is a logger based on the LogService.
- */
-class LogServiceSupport
-{
-
- private final LogService logService;
-
- public LogServiceSupport(final Object logService)
- {
- this.logService = (LogService) logService;
- }
-
- InternalLogger getLogger()
- {
- return new R6LogServiceLogger(this.logService);
- }
-}
\ No newline at end of file
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/R6LogServiceLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/R6LogServiceLogger.java
deleted file mode 100644
index f92303d85c..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/R6LogServiceLogger.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.felix.http.base.internal.logger;
-
-import org.osgi.service.log.LogService;
-
-/**
- * This is a logger based on the R6 LogService.
- */
-class R6LogServiceLogger implements InternalLogger
-{
- private final LogService logService;
-
- public R6LogServiceLogger(final LogService logService)
- {
- this.logService = logService;
- }
-
- @Override
- public boolean isLogEnabled(final int level)
- {
- return true;
- }
-
- @Override
- public void log(final int level, final String message, final Throwable ex)
- {
- this.logService.log(level, message, ex);
- }
-}
\ No newline at end of file
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
index ec7053397e..a8b2baeb15 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
@@ -21,30 +21,17 @@ package org.apache.felix.http.base.internal.logger;
import java.lang.reflect.Array;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public final class SystemLogger
-{
- private static volatile LogServiceEnabledLogger LOGGER;
+public final class SystemLogger {
- public static void init(final BundleContext bundleContext) {
- LOGGER = new LogServiceEnabledLogger(bundleContext);
- }
-
- public static void destroy() {
- if ( LOGGER != null ) {
- LOGGER.close();
- LOGGER = null;
- }
- }
+ public static final Logger LOGGER = LoggerFactory.getLogger("org.apache.felix.http");
- private static String getMessage(final ServiceReference<?> ref, final String message)
- {
- if ( ref == null )
- {
+ public static String formatMessage(final ServiceReference<?> ref, final String message) {
+ if ( ref == null ) {
return message;
}
final Bundle bundle = ref.getBundle();
@@ -52,15 +39,11 @@ public final class SystemLogger
ib.append("[ServiceReference ");
ib.append(String.valueOf(ref.getProperty(Constants.SERVICE_ID)));
ib.append(" from bundle ");
- if ( bundle == null )
- {
+ if ( bundle == null ) {
ib.append("<uninstalled>");
- }
- else
- {
+ } else {
ib.append(bundle.getBundleId());
- if ( bundle.getSymbolicName() != null )
- {
+ if ( bundle.getSymbolicName() != null ) {
ib.append(" : ");
ib.append(bundle.getSymbolicName());
ib.append(":");
@@ -71,39 +54,28 @@ public final class SystemLogger
ib.append(ref);
ib.append(" properties={");
boolean first = true;
- for(final String name : ref.getPropertyKeys())
- {
- if ( first )
- {
+ for(final String name : ref.getPropertyKeys()) {
+ if ( first ) {
first = false;
- }
- else
- {
+ } else {
ib.append(", ");
}
final Object val = ref.getProperty(name);
ib.append(name);
ib.append("=");
- if ( val.getClass().isArray() )
- {
+ if ( val.getClass().isArray() ) {
boolean fa = true;
ib.append('[');
- for(int i=0;i<Array.getLength(val);i++)
- {
- if ( fa )
- {
+ for(int i=0;i<Array.getLength(val);i++) {
+ if ( fa ) {
fa = false;
- }
- else
- {
+ } else {
ib.append(", ");
}
ib.append(Array.get(val, i));
}
- ib.append(']');
- }
- else
- {
+ ib.append(']');
+ } else {
ib.append(val);
}
}
@@ -112,50 +84,4 @@ public final class SystemLogger
return ib.toString();
}
-
- private static void log(
- final int level,
- final ServiceReference<?> ref,
- final String message,
- final Throwable cause) {
- final LogServiceEnabledLogger l = LOGGER;
- if ( l != null ) {
- l.log(level, getMessage(ref, message), cause);
- }
- }
-
- public static void debug(final String message)
- {
- log(LogService.LOG_DEBUG, null, message, null);
- }
-
- public static void debug(final ServiceReference<?> ref, final String message)
- {
- log(LogService.LOG_DEBUG, ref, message, null);
- }
-
- public static void debug(final String message, final Throwable cause)
- {
- log(LogService.LOG_DEBUG, null, message, cause);
- }
-
- public static void info(final String message)
- {
- log(LogService.LOG_INFO, null, message, null);
- }
-
- public static void warning(final String message, final Throwable cause)
- {
- log(LogService.LOG_WARNING, null, message, cause);
- }
-
- public static void error(final String message, final Throwable cause)
- {
- log(LogService.LOG_ERROR, null, message, cause);
- }
-
- public static void error(final ServiceReference<?> ref, final String message, final Throwable cause)
- {
- log(LogService.LOG_ERROR, ref, message, cause);
- }
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
index 5704968197..b2eea23333 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
@@ -210,7 +210,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -226,7 +226,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -242,7 +242,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -258,7 +258,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -274,7 +274,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -290,7 +290,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -306,7 +306,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -322,7 +322,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -338,7 +338,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -354,7 +354,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -370,7 +370,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -386,7 +386,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -402,7 +402,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -420,7 +420,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(null, "Exception while calling listener " + l, t);
+ SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
}
}
}
@@ -453,7 +453,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(info.getServiceReference(), "Exception while calling servlet context listener.", t);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(info.getServiceReference(), "Exception while calling servlet context listener."), t);
}
}
@@ -468,7 +468,7 @@ public final class EventListenerRegistry implements
}
catch (final Throwable t)
{
- SystemLogger.error(info.getServiceReference(), "Exception while calling servlet context listener.", t);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(info.getServiceReference(), "Exception while calling servlet context listener."), t);
}
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
index 0d370e4705..a7dfe63c92 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
@@ -116,16 +116,16 @@ public final class PerContextHandlerRegistry implements Comparable<PerContextHan
@Override
public int compareTo(@NotNull final PerContextHandlerRegistry other)
{
- final int result = new Integer(other.path.length()).compareTo(this.path.length());
+ final int result = Integer.valueOf(other.path.length()).compareTo(this.path.length());
if ( result == 0 ) {
if (this.ranking == other.ranking)
{
// Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
int reverseOrder = ( this.serviceId <= 0 && other.serviceId <= 0 ) ? -1 : 1;
- return reverseOrder * new Long(this.serviceId).compareTo(other.serviceId);
+ return reverseOrder * Long.valueOf(this.serviceId).compareTo(other.serviceId);
}
- return new Integer(other.ranking).compareTo(this.ranking);
+ return Integer.valueOf(other.ranking).compareTo(this.ranking);
}
return result;
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
index 6292afb3f8..ec9f7cdf9d 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
@@ -91,10 +91,10 @@ public abstract class AbstractInfo<T> implements Comparable<AbstractInfo<T>>
}
// Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
int reverseOrder = ( this.serviceId >= 0 && other.serviceId >= 0 ) ? 1 : -1;
- return reverseOrder * new Long(this.serviceId).compareTo(other.serviceId);
+ return reverseOrder * Long.valueOf(this.serviceId).compareTo(other.serviceId);
}
- int result = new Integer(other.ranking).compareTo(this.ranking);
+ int result = Integer.valueOf(other.ranking).compareTo(this.ranking);
return result;
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
index 1eb0352215..edf91414e1 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
@@ -121,7 +121,7 @@ public final class FailedDTOHolder
}
else
{
- SystemLogger.error("Unsupported info type: " + info.getClass(), null);
+ SystemLogger.LOGGER.error("Unsupported info type: {}", info.getClass());
}
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
index 359a8ded5c..6e76520f8c 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
@@ -107,7 +107,7 @@ public final class PerBundleHttpServiceImpl implements HttpService
}
catch (javax.servlet.ServletException e)
{
- SystemLogger.error("Failed to register resources", e);
+ SystemLogger.LOGGER.error("Failed to register resources", e);
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java
index 73f7f6485f..f3549161f3 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java
@@ -427,19 +427,19 @@ public class ServletContextImpl implements ExtServletContext
@Override
public void log(Exception cause, String message)
{
- SystemLogger.error(message, cause);
+ SystemLogger.LOGGER.error(message, cause);
}
@Override
public void log(String message)
{
- SystemLogger.info(message);
+ SystemLogger.LOGGER.info(message);
}
@Override
public void log(String message, Throwable cause)
{
- SystemLogger.error(message, cause);
+ SystemLogger.LOGGER.error(message, cause);
}
@Override
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/FailureStateHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/FailureStateHandler.java
index e85689d310..3d22095ab1 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/FailureStateHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/FailureStateHandler.java
@@ -78,31 +78,31 @@ public class FailureStateHandler {
}
if ( reason == FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING )
{
- SystemLogger.debug(ref, "Ignoring unmatching " + type + " service" + serviceInfo);
+ SystemLogger.LOGGER.debug(SystemLogger.formatMessage(ref, "Ignoring unmatching " + type + " service" + serviceInfo));
}
else if ( reason == FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE )
{
- SystemLogger.debug(ref, "Ignoring shadowed " + type + " service" + serviceInfo);
+ SystemLogger.LOGGER.debug(SystemLogger.formatMessage(ref, "Ignoring shadowed " + type + " service" + serviceInfo));
}
else if ( reason == FAILURE_REASON_SERVICE_NOT_GETTABLE )
{
- SystemLogger.error(ref, "Ignoring ungettable " + type + " service" + serviceInfo, ex);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(ref, "Ignoring ungettable " + type + " service" + serviceInfo), ex);
}
else if ( reason == FAILURE_REASON_VALIDATION_FAILED )
{
- SystemLogger.debug(ref, "Ignoring invalid " + type + " service" + serviceInfo);
+ SystemLogger.LOGGER.debug(SystemLogger.formatMessage(ref, "Ignoring invalid " + type + " service" + serviceInfo));
}
else if ( reason == FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING )
{
- SystemLogger.debug(ref, "Ignoring unmatched " + type + " service" + serviceInfo);
+ SystemLogger.LOGGER.debug(SystemLogger.formatMessage(ref, "Ignoring unmatched " + type + " service" + serviceInfo));
}
else if ( reason == FAILURE_REASON_SERVLET_CONTEXT_FAILURE )
{
- SystemLogger.debug(ref, "Servlet context " + String.valueOf(contextId) + " failure: Ignoring " + type + " service" + serviceInfo);
+ SystemLogger.LOGGER.debug(SystemLogger.formatMessage(ref, "Servlet context " + String.valueOf(contextId) + " failure: Ignoring " + type + " service" + serviceInfo));
}
else if ( reason == FAILURE_REASON_UNKNOWN)
{
- SystemLogger.error(ref, "Exception while registering " + type + " service" + serviceInfo, ex);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(ref, "Exception while registering " + type + " service" + serviceInfo), ex);
}
FailureStatus status = serviceFailures.get(info);
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
index 672c5f263f..eb6cd35c62 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
@@ -431,19 +431,19 @@ public class SharedServletContextImpl implements ServletContext
@Override
public void log(final Exception cause, final String message)
{
- SystemLogger.error(message, cause);
+ SystemLogger.LOGGER.error(message, cause);
}
@Override
public void log(final String message)
{
- SystemLogger.info(message);
+ SystemLogger.LOGGER.info(message);
}
@Override
public void log(final String message, final Throwable cause)
{
- SystemLogger.error(message, cause);
+ SystemLogger.LOGGER.error(message, cause);
}
@Override
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
index 18503f55d5..038cb2d37f 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
@@ -80,7 +80,6 @@ import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.servlet.context.ServletContextHelper;
-import org.osgi.service.servlet.runtime.HttpServiceRuntimeConstants;
import org.osgi.service.servlet.runtime.dto.DTOConstants;
import org.osgi.service.servlet.runtime.dto.PreprocessorDTO;
import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
@@ -874,7 +873,7 @@ public final class WhiteboardManager
else
{
// This should never happen, but we log anyway
- SystemLogger.error("Unknown whiteboard service " + info.getServiceReference(), null);
+ SystemLogger.LOGGER.error("Unknown whiteboard service {}", info.getServiceReference());
}
if ( failureCode != -1 )
{
@@ -920,7 +919,7 @@ public final class WhiteboardManager
}
catch (final Exception e)
{
- SystemLogger.error("Exception while unregistering whiteboard service " + info.getServiceReference(), e);
+ SystemLogger.LOGGER.error("Exception while unregistering whiteboard service {}", info.getServiceReference(), e);
}
}
@@ -942,7 +941,7 @@ public final class WhiteboardManager
catch ( final InvalidSyntaxException ise)
{
// log and ignore service
- SystemLogger.error("Invalid target filter expression for " + info.getServiceReference() + " : " + target, ise);
+ SystemLogger.LOGGER.error("Invalid target filter expression for {} : {}", info.getServiceReference(), target, ise);
return false;
}
}
diff --git a/http/bridge/pom.xml b/http/bridge/pom.xml
index c280958b8e..297c71e023 100644
--- a/http/bridge/pom.xml
+++ b/http/bridge/pom.xml
@@ -75,7 +75,6 @@
</Conditional-Package>
<Import-Package>
org.osgi.service.useradmin;resolution:=optional;version="[1.1,2)",
- org.osgi.service.log;resolution:=optional;version="[1.3,2)",
*
</Import-Package>
<Provide-Capability>
@@ -117,6 +116,12 @@
</build>
<dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.36</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
diff --git a/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java b/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
index bc89e9e031..4b63b82132 100644
--- a/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
+++ b/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
@@ -103,6 +103,6 @@ public final class BridgeActivator extends AbstractHttpActivator
props.put(Constants.SERVICE_VENDOR, VENDOR);
getBundleContext().registerService(EventListener.class.getName(), dispatcher, props);
- SystemLogger.info("Started bridged http services");
+ SystemLogger.LOGGER.info("Started bridged http services");
}
}
diff --git a/http/jetty/pom.xml b/http/jetty/pom.xml
index 8a25c11f69..2b55ab69a7 100644
--- a/http/jetty/pom.xml
+++ b/http/jetty/pom.xml
@@ -30,7 +30,7 @@
<description>This is an implementation of the R8.1 OSGi Servlet Service, the R7 OSGi Http Service and the R7 OSGi Http Whiteboard Specification</description>
<artifactId>org.apache.felix.http.jetty</artifactId>
- <version>5.0.0-RC2-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<scm>
@@ -409,7 +409,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.http.base</artifactId>
- <version>5.0.0-RC1</version>
+ <version>5.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
index 78e47008ef..08c706e337 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
@@ -60,7 +60,7 @@ public class ConnectorFactoryTracker extends ServiceTracker<ConnectorFactory, Co
connector.start();
return connector;
} catch (Exception e) {
- SystemLogger.error("Failed starting connector '" + connector + "' provided by " + reference, e);
+ SystemLogger.LOGGER.error("Failed starting connector '{}' provided by {}", connector, reference, e);
}
// connector failed to start, don't continue tracking
ServiceUtils.safeUngetService(context, reference);
@@ -80,7 +80,7 @@ public class ConnectorFactoryTracker extends ServiceTracker<ConnectorFactory, Co
}
catch (Exception e)
{
- SystemLogger.info("Failed stopping connector '" + connector + "' provided by " + reference + ": " + e);
+ SystemLogger.LOGGER.info("Failed stopping connector '{}' provided by {}", connector, reference, e);
}
}
this.server.removeConnector(connector);
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 21ec142981..8efd1b34cf 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
@@ -63,7 +63,7 @@ class FileRequestLog {
File logFile = new File(logFilePath).getAbsoluteFile();
File logFileDir = logFile.getParentFile();
if (logFileDir != null && !logFileDir.isDirectory()) {
- SystemLogger.info("Creating directory " + logFileDir.getAbsolutePath());
+ SystemLogger.LOGGER.info("Creating directory {}", logFileDir.getAbsolutePath());
Files.createDirectories(logFileDir.toPath(), PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")));
}
@@ -77,7 +77,7 @@ class FileRequestLog {
svcProps.put(SVC_PROP_FILEPATH, logFilePath);
registration = context.registerService(RequestLog.class, delegate, svcProps);
} catch (Exception e) {
- SystemLogger.error("Error starting File Request Log", e);
+ SystemLogger.LOGGER.error("Error starting File Request Log", e);
}
}
@@ -88,7 +88,7 @@ class FileRequestLog {
}
delegate.stop();
} catch (Exception e) {
- SystemLogger.error("Error shutting down File Request Log", e);
+ SystemLogger.LOGGER.error("Error shutting down File Request Log", e);
} finally {
registration = null;
}
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 66acd728ea..91b561ab0f 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
@@ -847,7 +847,7 @@ public final class JettyConfig
}
catch (IOException e)
{
- SystemLogger.debug("Unable to bind to port: " + i);
+ SystemLogger.LOGGER.debug("Unable to bind to port: {}", i);
}
finally
{
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
index ec1702c660..db750818bb 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
@@ -75,7 +75,7 @@ public class JettyManagedServiceFactory implements ManagedServiceFactory, Closea
}
catch (final Exception e)
{
- SystemLogger.error("Failed to start Http Jetty pid=" + pid, e);
+ SystemLogger.LOGGER.error("Failed to start Http Jetty pid={}", pid, e);
}
}
@@ -92,7 +92,7 @@ public class JettyManagedServiceFactory implements ManagedServiceFactory, Closea
}
catch (Exception e)
{
- SystemLogger.error("Faiiled to stop Http Jetty pid=" + pid, e);
+ SystemLogger.LOGGER.error("Faiiled to stop Http Jetty pid={}", pid, e);
}
}
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index 8252214f7f..4b7c32b784 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -175,7 +175,7 @@ public final class JettyService
}
catch (Exception e)
{
- SystemLogger.error("Exception while initializing Jetty.", e);
+ SystemLogger.LOGGER.error("Exception while initializing Jetty", e);
}
}
@@ -218,11 +218,11 @@ public final class JettyService
{
this.server.stop();
this.server = null;
- SystemLogger.info("Stopped Jetty.");
+ SystemLogger.LOGGER.info("Stopped Jetty");
}
catch (Exception e)
{
- SystemLogger.error("Exception while stopping Jetty.", e);
+ SystemLogger.LOGGER.error("Exception while stopping Jetty", e);
}
if (this.mbeanServerTracker != null)
@@ -356,13 +356,13 @@ public final class JettyService
}
message.append("]");
- SystemLogger.info(message.toString());
+ SystemLogger.LOGGER.info(message.toString());
this.controller.register(context.getServletContext(), getServiceProperties());
}
else
{
this.stopJetty();
- SystemLogger.error("Jetty stopped (no connectors available)", null);
+ SystemLogger.LOGGER.error("Jetty stopped (no connectors available)");
}
try {
@@ -370,24 +370,24 @@ public final class JettyService
this.requestLogTracker.open();
this.server.setRequestLog(requestLogTracker);
} catch (InvalidSyntaxException e) {
- SystemLogger.error("Invalid filter syntax in request log tracker", e);
+ SystemLogger.LOGGER.error("Invalid filter syntax in request log tracker", e);
}
if (this.config.isRequestLogOSGiEnabled()) {
this.osgiRequestLog = new LogServiceRequestLog(this.config);
this.osgiRequestLog.register(this.context);
- SystemLogger.info("Directing Jetty request logs to the OSGi Log Service");
+ SystemLogger.LOGGER.info("Directing Jetty request logs to the OSGi Log Service");
}
if (this.config.getRequestLogFilePath() != null && !this.config.getRequestLogFilePath().isEmpty()) {
this.fileRequestLog = new FileRequestLog(config);
this.fileRequestLog.start(this.context);
- SystemLogger.info("Directing Jetty request logs to " + this.config.getRequestLogFilePath());
+ SystemLogger.LOGGER.info("Directing Jetty request logs to {}", this.config.getRequestLogFilePath());
}
}
else
{
- SystemLogger.warning("Jetty not started (HTTP and HTTPS disabled)", null);
+ SystemLogger.LOGGER.warn("Jetty not started (HTTP and HTTPS disabled)");
}
}
@@ -601,7 +601,7 @@ public final class JettyService
catch (Exception e)
{
this.server.removeConnector(connector);
- SystemLogger.error("Failed to start Connector: " + connector, e);
+ SystemLogger.LOGGER.error("Failed to start Connector: {}", connector, e);
}
return false;
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 8ccbdec260..13bed447a1 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
@@ -44,7 +44,7 @@ class LogServiceRequestLog extends CustomRequestLog {
@Override
public void write(String requestEntry) throws IOException {
- SystemLogger.info(PREFIX.concat(requestEntry));
+ SystemLogger.LOGGER.info(PREFIX.concat(requestEntry));
}
},config.getRequestLogOSGiFormat());
this.serviceName = config.getRequestLogOSGiServiceName();
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
index ba93584b9f..25640d959a 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
@@ -98,8 +98,8 @@ class RequestLogTracker extends ServiceTracker<RequestLog, RequestLog> implemen
* error limit.
*/
private void processError(ServiceReference<?> reference, Exception e) {
- SystemLogger.error(reference, String.format("Error dispatching to request log service ID %d from bundle %s:%s",
- reference.getProperty(Constants.SERVICE_ID), reference.getBundle().getSymbolicName(), reference.getBundle().getVersion()), e);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(reference, String.format("Error dispatching to request log service ID %d from bundle %s:%s",
+ reference.getProperty(Constants.SERVICE_ID), reference.getBundle().getSymbolicName(), reference.getBundle().getVersion())), e);
int naughty = naughtyStep.merge(reference, 1, Integer::sum);
if (naughty >= MAX_ERROR_COUNT) {
@@ -107,8 +107,8 @@ class RequestLogTracker extends ServiceTracker<RequestLog, RequestLog> implemen
// so we will not invoke the service again.
logSvcs.remove(reference);
naughtyStep.remove(reference);
- SystemLogger.error(reference, String.format("RequestLog service ID %d from bundle %s:%s threw too many errors, it will no longer be invoked.",
- reference.getProperty(Constants.SERVICE_ID), reference.getBundle().getSymbolicName(), reference.getBundle().getVersion()), null);
+ SystemLogger.LOGGER.error(SystemLogger.formatMessage(reference, String.format("RequestLog service ID %d from bundle %s:%s threw too many errors, it will no longer be invoked.",
+ reference.getProperty(Constants.SERVICE_ID), reference.getBundle().getSymbolicName(), reference.getBundle().getVersion())));
}
}
}
diff --git a/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/RequestLogTrackerTest.java b/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/RequestLogTrackerTest.java
index 47ffd553e3..6cce1a3103 100644
--- a/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/RequestLogTrackerTest.java
+++ b/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/RequestLogTrackerTest.java
@@ -78,6 +78,7 @@ public class RequestLogTrackerTest {
}
};
ServiceReference<RequestLog> mockSvcRef = mock(ServiceReference.class);
+ when(mockSvcRef.getPropertyKeys()).thenReturn(new String[0]);
Bundle mockBundle = mock(Bundle.class);
when(mockSvcRef.getBundle()).thenReturn(mockBundle);
when(mockBundle.getSymbolicName()).thenReturn("org.example");