diff --git a/apache-jsp/pom.xml b/apache-jsp/pom.xml index 4220f823685..4b0a2b9ddd1 100644 --- a/apache-jsp/pom.xml +++ b/apache-jsp/pom.xml @@ -63,6 +63,10 @@ + + org.slf4j + slf4j-api + org.eclipse.jetty jetty-util diff --git a/apache-jsp/src/main/java/module-info.java b/apache-jsp/src/main/java/module-info.java index 18545591505..018320716a0 100644 --- a/apache-jsp/src/main/java/module-info.java +++ b/apache-jsp/src/main/java/module-info.java @@ -29,6 +29,7 @@ module org.eclipse.jetty.apache.jsp requires java.xml; requires jetty.servlet.api; + requires org.slf4j; requires org.eclipse.jetty.util; requires org.mortbay.apache.jasper; diff --git a/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JuliLog.java b/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JuliLog.java index 961a0de9125..b85aecfbabc 100644 --- a/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JuliLog.java +++ b/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JuliLog.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.apache.jsp; +import org.slf4j.LoggerFactory; + public class JuliLog implements org.apache.juli.logging.Log { public static org.apache.juli.logging.Log getInstance(String name) @@ -25,19 +27,16 @@ public class JuliLog implements org.apache.juli.logging.Log return new JuliLog(name); } - private final org.eclipse.jetty.util.log.Logger _logger; - private final org.eclipse.jetty.util.log.StdErrLog _stdErrLog; + private final org.slf4j.Logger _logger; public JuliLog() { - _logger = org.eclipse.jetty.util.log.Log.getRootLogger(); - _stdErrLog = (_logger instanceof org.eclipse.jetty.util.log.StdErrLog) ? (org.eclipse.jetty.util.log.StdErrLog)_logger : null; + _logger = LoggerFactory.getLogger(""); } public JuliLog(String name) { - _logger = org.eclipse.jetty.util.log.Log.getLogger(name); - _stdErrLog = (_logger instanceof org.eclipse.jetty.util.log.StdErrLog) ? (org.eclipse.jetty.util.log.StdErrLog)_logger : null; + _logger = LoggerFactory.getLogger(name); } @Override @@ -49,31 +48,31 @@ public class JuliLog implements org.apache.juli.logging.Log @Override public boolean isErrorEnabled() { - return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN; + return _logger.isErrorEnabled(); } @Override public boolean isFatalEnabled() { - return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN; + return _logger.isErrorEnabled(); } @Override public boolean isInfoEnabled() { - return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_INFO; + return _logger.isInfoEnabled(); } @Override public boolean isTraceEnabled() { - return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_DEBUG; + return _logger.isTraceEnabled(); } @Override public boolean isWarnEnabled() { - return _stdErrLog == null ? true : _stdErrLog.getLevel() <= org.eclipse.jetty.util.log.StdErrLog.LEVEL_WARN; + return _logger.isWarnEnabled(); } @Override diff --git a/apache-jstl/src/test/resources/jetty-logging.properties b/apache-jstl/src/test/resources/jetty-logging.properties index 08befa5ce97..c1f44baf179 100644 --- a/apache-jstl/src/test/resources/jetty-logging.properties +++ b/apache-jstl/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=INFO # org.eclipse.jetty.util.LEVEL=DEBUG diff --git a/examples/embedded/pom.xml b/examples/embedded/pom.xml index 04785ddabf4..7dceec94289 100644 --- a/examples/embedded/pom.xml +++ b/examples/embedded/pom.xml @@ -15,6 +15,14 @@ ${project.groupId}.embedded + + org.slf4j + slf4j-api + + + org.eclipse.jetty + jetty-slf4j-impl + org.eclipse.jetty jetty-util-ajax diff --git a/examples/embedded/src/main/resources/jetty-logging.properties b/examples/embedded/src/main/resources/jetty-logging.properties index c0a226179d4..b7d93c80293 100644 --- a/examples/embedded/src/main/resources/jetty-logging.properties +++ b/examples/embedded/src/main/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog +## Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.util.log.javautil.PROPERTIES=java-util-logging.properties #org.eclipse.jetty.util.log.SOURCE=true #org.eclipse.jetty.LEVEL=INFO diff --git a/examples/embedded/src/test/resources/jetty-logging.properties b/examples/embedded/src/test/resources/jetty-logging.properties index b86623fd081..ce01e8bace1 100644 --- a/examples/embedded/src/test/resources/jetty-logging.properties +++ b/examples/embedded/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=INFO org.eclipse.jetty.embedded.JettyDistribution.LEVEL=DEBUG #org.eclipse.jetty.STACKS=true diff --git a/jetty-alpn/jetty-alpn-client/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-client/src/main/java/module-info.java index f66048b405f..d047028c69c 100644 --- a/jetty-alpn/jetty-alpn-client/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-client/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.alpn.client exports org.eclipse.jetty.alpn.client; requires transitive org.eclipse.jetty.io; + requires org.slf4j; uses ALPNProcessor.Client; } diff --git a/jetty-alpn/jetty-alpn-conscrypt-client/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-conscrypt-client/src/main/java/module-info.java index 3d9a92407d8..baccbefede3 100644 --- a/jetty-alpn/jetty-alpn-conscrypt-client/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-conscrypt-client/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.alpn.conscrypt.client { requires org.conscrypt; requires transitive org.eclipse.jetty.alpn.client; + requires org.slf4j; provides ALPNProcessor.Client with ConscryptClientALPNProcessor; } diff --git a/jetty-alpn/jetty-alpn-conscrypt-client/src/test/resources/jetty-logging.properties b/jetty-alpn/jetty-alpn-conscrypt-client/src/test/resources/jetty-logging.properties index d96a696f82e..56cc73e5d68 100644 --- a/jetty-alpn/jetty-alpn-conscrypt-client/src/test/resources/jetty-logging.properties +++ b/jetty-alpn/jetty-alpn-conscrypt-client/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG diff --git a/jetty-alpn/jetty-alpn-conscrypt-server/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-conscrypt-server/src/main/java/module-info.java index 3a5a872ca3b..a78a2135e81 100644 --- a/jetty-alpn/jetty-alpn-conscrypt-server/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-conscrypt-server/src/main/java/module-info.java @@ -22,6 +22,7 @@ import org.eclipse.jetty.io.ssl.ALPNProcessor; module org.eclipse.jetty.alpn.conscrypt.server { requires org.conscrypt; + requires org.slf4j; requires transitive org.eclipse.jetty.alpn.server; provides ALPNProcessor.Server with ConscryptServerALPNProcessor; diff --git a/jetty-alpn/jetty-alpn-conscrypt-server/src/test/resources/jetty-logging.properties b/jetty-alpn/jetty-alpn-conscrypt-server/src/test/resources/jetty-logging.properties index c391f84e35b..2f2fa6d19d9 100644 --- a/jetty-alpn/jetty-alpn-conscrypt-server/src/test/resources/jetty-logging.properties +++ b/jetty-alpn/jetty-alpn-conscrypt-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.alpn.LEVEL=DEBUG diff --git a/jetty-alpn/jetty-alpn-java-client/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-java-client/src/main/java/module-info.java index 2ba4756950c..8496f7fe5e6 100644 --- a/jetty-alpn/jetty-alpn-java-client/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-java-client/src/main/java/module-info.java @@ -22,6 +22,7 @@ import org.eclipse.jetty.io.ssl.ALPNProcessor; module org.eclipse.jetty.alpn.java.client { requires transitive org.eclipse.jetty.alpn.client; + requires org.slf4j; provides ALPNProcessor.Client with JDK9ClientALPNProcessor; } diff --git a/jetty-alpn/jetty-alpn-java-client/src/test/resources/jetty-logging.properties b/jetty-alpn/jetty-alpn-java-client/src/test/resources/jetty-logging.properties index d96a696f82e..56cc73e5d68 100644 --- a/jetty-alpn/jetty-alpn-java-client/src/test/resources/jetty-logging.properties +++ b/jetty-alpn/jetty-alpn-java-client/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG diff --git a/jetty-alpn/jetty-alpn-java-server/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-java-server/src/main/java/module-info.java index f34903c4cbb..3dc66cb7ad2 100644 --- a/jetty-alpn/jetty-alpn-java-server/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-java-server/src/main/java/module-info.java @@ -21,6 +21,7 @@ import org.eclipse.jetty.io.ssl.ALPNProcessor; module org.eclipse.jetty.alpn.java.server { + requires org.slf4j; requires transitive org.eclipse.jetty.alpn.server; provides ALPNProcessor.Server with JDK9ServerALPNProcessor; diff --git a/jetty-alpn/jetty-alpn-java-server/src/test/resources/jetty-logging.properties b/jetty-alpn/jetty-alpn-java-server/src/test/resources/jetty-logging.properties index c391f84e35b..2f2fa6d19d9 100644 --- a/jetty-alpn/jetty-alpn-java-server/src/test/resources/jetty-logging.properties +++ b/jetty-alpn/jetty-alpn-java-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.alpn.LEVEL=DEBUG diff --git a/jetty-alpn/jetty-alpn-server/src/main/java/module-info.java b/jetty-alpn/jetty-alpn-server/src/main/java/module-info.java index 395048acd64..c0e6b7e1452 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/java/module-info.java +++ b/jetty-alpn/jetty-alpn-server/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.alpn.server exports org.eclipse.jetty.alpn.server; requires transitive org.eclipse.jetty.server; + requires org.slf4j; uses ALPNProcessor.Server; } diff --git a/jetty-annotations/src/main/java/module-info.java b/jetty-annotations/src/main/java/module-info.java index bca49e300ef..6575c28d572 100644 --- a/jetty-annotations/src/main/java/module-info.java +++ b/jetty-annotations/src/main/java/module-info.java @@ -29,6 +29,7 @@ module org.eclipse.jetty.annotations requires java.naming; requires transitive org.eclipse.jetty.plus; requires transitive org.objectweb.asm; + requires org.slf4j; uses ServletContainerInitializer; diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationIntrospector.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationIntrospector.java index d2ff57d8a82..6458daa52bd 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationIntrospector.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationIntrospector.java @@ -20,10 +20,10 @@ package org.eclipse.jetty.annotations; import java.io.File; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.Source; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.FragmentDescriptor; import org.eclipse.jetty.webapp.WebAppContext; diff --git a/jetty-annotations/src/test/resources/jetty-logging.properties b/jetty-annotations/src/test/resources/jetty-logging.properties index fff7f1b3e39..9c9f7d77b57 100644 --- a/jetty-annotations/src/test/resources/jetty-logging.properties +++ b/jetty-annotations/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.annotations.LEVEL=DEBUG diff --git a/jetty-client/pom.xml b/jetty-client/pom.xml index b1c935b2f6f..e859d380e22 100644 --- a/jetty-client/pom.xml +++ b/jetty-client/pom.xml @@ -24,7 +24,6 @@ @{argLine} ${jetty.surefire.argLine} --add-modules java.security.jgss --add-modules org.eclipse.jetty.jmx - --add-modules org.slf4j @@ -157,11 +156,10 @@ org.slf4j slf4j-api - test - org.slf4j - slf4j-simple + org.eclipse.jetty + jetty-slf4j-impl test diff --git a/jetty-client/src/main/java/module-info.java b/jetty-client/src/main/java/module-info.java index 5f5443c19a3..633e74db434 100644 --- a/jetty-client/src/main/java/module-info.java +++ b/jetty-client/src/main/java/module-info.java @@ -28,6 +28,7 @@ module org.eclipse.jetty.client requires org.eclipse.jetty.alpn.client; requires transitive org.eclipse.jetty.http; + requires org.slf4j; // Only required if using SPNEGO. requires static java.security.jgss; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index aff6cd24616..868fc335bb4 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -82,6 +82,7 @@ import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.Net; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; @@ -92,7 +93,6 @@ import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.SocketAddressResolver; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.condition.DisabledIfSystemProperty; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java index c0d4aba223c..733cb78f873 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java @@ -35,9 +35,9 @@ import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.util.ByteBufferContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.condition.DisabledIfSystemProperty; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java index d16996c8e26..aca7bb99461 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java @@ -33,9 +33,9 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.util.ByteBufferContentProvider; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; diff --git a/jetty-client/src/test/resources/jetty-logging.properties b/jetty-client/src/test/resources/jetty-logging.properties index f74a4da98d1..e6bbf9a6ca0 100644 --- a/jetty-client/src/test/resources/jetty-logging.properties +++ b/jetty-client/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.io.ChannelEndPoint.LEVEL=DEBUG diff --git a/jetty-deploy/pom.xml b/jetty-deploy/pom.xml index 45376093155..68ace6744ea 100644 --- a/jetty-deploy/pom.xml +++ b/jetty-deploy/pom.xml @@ -51,6 +51,10 @@ ${project.version} true + + org.slf4j + slf4j-api + org.eclipse.jetty.toolchain diff --git a/jetty-deploy/src/main/java/module-info.java b/jetty-deploy/src/main/java/module-info.java index 7e2365477db..783914725a3 100644 --- a/jetty-deploy/src/main/java/module-info.java +++ b/jetty-deploy/src/main/java/module-info.java @@ -27,6 +27,7 @@ module org.eclipse.jetty.deploy requires java.xml; requires transitive org.eclipse.jetty.webapp; requires org.eclipse.jetty.xml; + requires org.slf4j; // Only required if using JMX. requires static org.eclipse.jetty.jmx; diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/BadAppDeployTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/BadAppDeployTest.java index ef65d445de8..0c99e06d673 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/BadAppDeployTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/BadAppDeployTest.java @@ -24,6 +24,7 @@ import java.nio.file.Path; import javax.servlet.ServletException; import org.eclipse.jetty.deploy.providers.WebAppProvider; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -33,12 +34,11 @@ import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.LoggerFactory; import static java.time.Duration.ofSeconds; import static org.hamcrest.MatcherAssert.assertThat; @@ -103,10 +103,9 @@ public class BadAppDeployTest assertTimeoutPreemptively(ofSeconds(10), () -> { - - try (StacklessLogging ignore = new StacklessLogging(Log.getLogger(WebAppContext.class), - Log.getLogger(DeploymentManager.class), - Log.getLogger("org.eclipse.jetty.server.handler.ContextHandler.badapp"))) + try (StacklessLogging ignore = new StacklessLogging(LoggerFactory.getLogger(WebAppContext.class), + LoggerFactory.getLogger(DeploymentManager.class), + LoggerFactory.getLogger("org.eclipse.jetty.server.handler.ContextHandler.badapp"))) { ServletException cause = assertThrows(ServletException.class, () -> server.start()); assertThat(cause.getMessage(), containsString("intentionally")); @@ -157,9 +156,9 @@ public class BadAppDeployTest assertTimeoutPreemptively(ofSeconds(10), () -> { - try (StacklessLogging ignore = new StacklessLogging(Log.getLogger(WebAppContext.class), - Log.getLogger(DeploymentManager.class), - Log.getLogger("org.eclipse.jetty.server.handler.ContextHandler.badapp"))) + try (StacklessLogging ignore = new StacklessLogging(LoggerFactory.getLogger(WebAppContext.class), + LoggerFactory.getLogger(DeploymentManager.class), + LoggerFactory.getLogger("org.eclipse.jetty.server.handler.ContextHandler.badapp"))) { ServletException cause = assertThrows(ServletException.class, () -> server.start()); assertThat(cause.getMessage(), containsString("intentionally")); diff --git a/jetty-deploy/src/test/resources/jetty-logging.properties b/jetty-deploy/src/test/resources/jetty-logging.properties index 0a15aa423f2..363b21c3fb0 100644 --- a/jetty-deploy/src/test/resources/jetty-logging.properties +++ b/jetty-deploy/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.deploy.LEVEL=WARN org.eclipse.jetty.util.Scanner=WARN #org.eclipse.jetty.webapp.LEVEL=DEBUG diff --git a/jetty-fcgi/fcgi-client/src/main/java/module-info.java b/jetty-fcgi/fcgi-client/src/main/java/module-info.java index 49d6ceab44e..bb5bcb07fe3 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/module-info.java +++ b/jetty-fcgi/fcgi-client/src/main/java/module-info.java @@ -24,4 +24,5 @@ module org.eclipse.jetty.fcgi.client exports org.eclipse.jetty.fcgi.parser; requires transitive org.eclipse.jetty.client; + requires org.slf4j; } diff --git a/jetty-fcgi/fcgi-client/src/test/resources/jetty-logging.properties b/jetty-fcgi/fcgi-client/src/test/resources/jetty-logging.properties index b8df62d071d..4e7406f1b54 100644 --- a/jetty-fcgi/fcgi-client/src/test/resources/jetty-logging.properties +++ b/jetty-fcgi/fcgi-client/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.fcgi.LEVEL=DEBUG diff --git a/jetty-fcgi/fcgi-server/pom.xml b/jetty-fcgi/fcgi-server/pom.xml index 742fcf5a9fe..6b8cd246e86 100644 --- a/jetty-fcgi/fcgi-server/pom.xml +++ b/jetty-fcgi/fcgi-server/pom.xml @@ -15,6 +15,10 @@ + + org.slf4j + slf4j-api + org.eclipse.jetty.toolchain jetty-servlet-api diff --git a/jetty-fcgi/fcgi-server/src/main/java/module-info.java b/jetty-fcgi/fcgi-server/src/main/java/module-info.java index bf0cac53d6e..c4201e8cd37 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/module-info.java +++ b/jetty-fcgi/fcgi-server/src/main/java/module-info.java @@ -21,6 +21,7 @@ module org.eclipse.jetty.fcgi.server exports org.eclipse.jetty.fcgi.server; exports org.eclipse.jetty.fcgi.server.proxy; + requires org.slf4j; requires transitive org.eclipse.jetty.fcgi.client; requires transitive org.eclipse.jetty.proxy; diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java index 2d2e7c6b939..f842f7f9ecd 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java @@ -260,7 +260,7 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent fcgi.put(field.getName(), field.getValue()); } String eol = System.lineSeparator(); - _log.debug("FastCGI variables{}{}", eol, fcgi.entrySet().stream() + _log.debug("FastCGI variables {}{}", eol, fcgi.entrySet().stream() .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue())) .collect(Collectors.joining(eol))); } diff --git a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java index 704d4a64f90..f2727aab175 100644 --- a/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java +++ b/jetty-fcgi/fcgi-server/src/test/java/org/eclipse/jetty/fcgi/server/HttpClientTest.java @@ -45,11 +45,11 @@ import org.eclipse.jetty.client.util.DeferredContentProvider; import org.eclipse.jetty.client.util.FutureResponseListener; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.io.MappedByteBufferPool; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.Net; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledIfSystemProperty; diff --git a/jetty-fcgi/fcgi-server/src/test/resources/jetty-logging.properties b/jetty-fcgi/fcgi-server/src/test/resources/jetty-logging.properties index b8df62d071d..4e7406f1b54 100644 --- a/jetty-fcgi/fcgi-server/src/test/resources/jetty-logging.properties +++ b/jetty-fcgi/fcgi-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.fcgi.LEVEL=DEBUG diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/main/config-template/modules/gcloud-datastore.mod b/jetty-gcloud/jetty-gcloud-session-manager/src/main/config-template/modules/gcloud-datastore.mod index 9415b77ed9d..11dbd23f2ff 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/main/config-template/modules/gcloud-datastore.mod +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/main/config-template/modules/gcloud-datastore.mod @@ -9,6 +9,6 @@ gcloud [depends] gcloud -jcl-slf4j -jul-impl +logging-jcl-capture +logging-jul diff --git a/jetty-home/pom.xml b/jetty-home/pom.xml index 85c5da33771..dc26067f8f8 100644 --- a/jetty-home/pom.xml +++ b/jetty-home/pom.xml @@ -170,6 +170,33 @@ ${source-assembly-directory}/lib + + copy-lib-logging-deps + generate-resources + + copy-dependencies + + + org.eclipse.jetty,org.slf4j + jetty-slf4j-impl,slf4j-api + jar + ${assembly-directory}/lib/logging + + + + copy-lib-logging-src-deps + generate-resources + + copy-dependencies + + + org.eclipse.jetty,org.slf4j + jetty-slf4j-impl,slf4j-api + jar + sources + ${source-assembly-directory}/lib/logging + + copy-lib-websocket-deps generate-resources @@ -603,6 +630,11 @@ + + org.eclipse.jetty + jetty-slf4j-impl + ${project.version} + org.eclipse.jetty jetty-deploy diff --git a/jetty-home/src/main/resources/etc/logging-jul-capture.xml b/jetty-home/src/main/resources/etc/logging-jul-capture.xml new file mode 100644 index 00000000000..a701abe77c1 --- /dev/null +++ b/jetty-home/src/main/resources/etc/logging-jul-capture.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/jetty-util/src/main/config/modules/slf4j-api.mod b/jetty-home/src/main/resources/modules/logging-jcl-capture.mod similarity index 74% rename from jetty-util/src/main/config/modules/slf4j-api.mod rename to jetty-home/src/main/resources/modules/logging-jcl-capture.mod index 70c7b548249..78f59c7fb1b 100644 --- a/jetty-util/src/main/config/modules/slf4j-api.mod +++ b/jetty-home/src/main/resources/modules/logging-jcl-capture.mod @@ -1,23 +1,23 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html [description] -Provides SLF4J API. Requires a slf4j implementation (eg slf4j-simple-impl) -otherwise a noop implementation is used. +Capture jakarta-commons-logging events and bridge them to org.slf4j [tags] logging -slf4j -internal + +[depends] +logging/slf4j +logging + +[provides] +commons-logging [files] -maven://org.slf4j/slf4j-api/${slf4j.version}|lib/slf4j/slf4j-api-${slf4j.version}.jar +maven://org.slf4j/jcl-over-slf4j/%{slf4j.version}|jcl-over-slf4j-${slf4j.version}.jar [lib] -lib/slf4j/slf4j-api-${slf4j.version}.jar - -[ini] -slf4j.version?=1.8.0-beta2 -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/slf4j/ +lib/logging/jcl-over-slf4j-${slf4j.version}.jar [license] SLF4J is distributed under the MIT License. @@ -42,3 +42,5 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + diff --git a/jetty-home/src/main/resources/modules/logging-jetty.mod b/jetty-home/src/main/resources/modules/logging-jetty.mod new file mode 100644 index 00000000000..71da0e34905 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-jetty.mod @@ -0,0 +1,24 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure jetty logging mechanism. +Provides a ${jetty.base}/resources/jetty-logging.properties. + +[tags] +logging + +[depends] +logging/slf4j +resources + +[provides] +logging|default + +[files] +basehome:modules/logging/jetty + +[lib] +lib/logging/jetty-slf4j-impl-${jetty.version}.jar + +[ini] +jetty.webapp.addServerClasses+=,org.eclipse.jetty.logging. diff --git a/jetty-home/src/main/resources/modules/logging-jul-capture.mod b/jetty-home/src/main/resources/modules/logging-jul-capture.mod new file mode 100644 index 00000000000..5401a052c17 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-jul-capture.mod @@ -0,0 +1,47 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Capture java.util.logging events and bridge them to org.slf4j + +[tags] +logging + +[depends] +logging/slf4j +logging + +[provides] +java-util-logging + +[xml] +etc/logging-jul-capture.xml + +[files] +maven://org.slf4j/jul-to-slf4j/%{slf4j.version}|jul-to-slf4j-${slf4j.version}.jar + +[lib] +lib/logging/jul-to-slf4j-${slf4j.version}.jar + +[license] +SLF4J is distributed under the MIT License. +Copyright (c) 2004-2013 QOS.ch +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/jetty-home/src/main/resources/modules/logging-jul.mod b/jetty-home/src/main/resources/modules/logging-jul.mod new file mode 100644 index 00000000000..4bf63a0924b --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-jul.mod @@ -0,0 +1,53 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure jetty logging to use Java Util Logging (jul) +SLF4J is used as the core logging mechanism. + +[tags] +logging + +[depends] +logging/slf4j +resources + +[provides] +logging +java-util-logging + +[files] +basehome:modules/logging/jul +maven://org.slf4j/slf4j-jdk14/${slf4j.version}|lib/logging/slf4j-jdk14-${slf4j.version}.jar + +[lib] +lib/logging/slf4j-jdk14-${slf4j.version}.jar + +[ini] +slf4j.version?=2.0.0-alpha1 +java.util.logging.config.file=${jetty.base}/resources/java-util-logging.properties + +[license] +SLF4J is distributed under the MIT License. +Copyright (c) 2004-2013 QOS.ch +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + diff --git a/jetty-home/src/main/resources/modules/logging-log4j1-capture.mod b/jetty-home/src/main/resources/modules/logging-log4j1-capture.mod new file mode 100644 index 00000000000..41dca46cf85 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-log4j1-capture.mod @@ -0,0 +1,44 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Capture Apache log4j events and bridge them to org.slf4j + +[tags] +logging + +[depends] +logging/slf4j +logging + +[provides] +log4j + +[files] +maven://org.slf4j/jcl-over-slf4j/%{slf4j.version}|jcl-over-slf4j-${slf4j.version}.jar + +[lib] +lib/logging/log4j-to-slf4j-${slf4j.version}.jar + +[license] +SLF4J is distributed under the MIT License. +Copyright (c) 2004-2013 QOS.ch +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/jetty-home/src/main/resources/modules/logging-log4j1.mod b/jetty-home/src/main/resources/modules/logging-log4j1.mod new file mode 100644 index 00000000000..ef7332070e7 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-log4j1.mod @@ -0,0 +1,58 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure jetty logging to use Log4j Logging +SLF4J is used as the core logging mechanism. + +[tags] +logging + +[depends] +logging/slf4j +resources + +[provides] +logging +log4j + +[files] +basehome:modules/logging/log4j1 +maven://log4j/log4j/${log4j.version}|lib/logging/log4j-${log4j.version}.jar +maven://org.slf4j/slf4j-log4j12/${slf4j.version}|lib/logging/slf4j-log4j12-${slf4j.version}.jar + +[lib] +lib/logging/slf4j-log4j12-${slf4j.version}.jar +lib/logging/log4j-${log4j.version}.jar + +[ini] +log4j.version?=1.2.17 +jetty.webapp.addServerClasses+=,org.apache.log4j. + + +[license] +Log4j is released under the Apache 2.0 license. +http://www.apache.org/licenses/LICENSE-2.0.html + + +SLF4J is distributed under the MIT License. +Copyright (c) 2004-2013 QOS.ch +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/jetty-home/src/main/resources/modules/logging-log4j2.mod b/jetty-home/src/main/resources/modules/logging-log4j2.mod new file mode 100644 index 00000000000..784320b33ab --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-log4j2.mod @@ -0,0 +1,35 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure jetty logging to use log4j version 2 +SLF4J is used as the core logging mechanism. + +[tags] +logging + +[depends] +logging/slf4j +resources + +[provides] +logging +log4j + +[files] +basehome:modules/logging/log4j2 +maven://org.apache.logging.log4j/log4j-slf4j18-impl/${log4j.version}|lib/logging/log4j-slf4j18-impl-${log4j.version}.jar +maven://org.apache.logging.log4j/log4j-api/${log4j.version}|lib/logging/log4j-api-${log4j.version}.jar +maven://org.apache.logging.log4j/log4j-core/${log4j.version}|lib/logging/log4j-core-${log4j.version}.jar + +[lib] +lib/logging/log4j-slf4j18-impl-${log4j.version}.jar +lib/logging/log4j-api-${log4j.version}.jar +lib/logging/log4j-core-${log4j.version}.jar + +[ini] +log4j.version?=2.13.0 +jetty.webapp.addServerClasses+=,org.apache.logging.log4j. + +[license] +Log4j is released under the Apache 2.0 license. +http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/jetty-home/src/main/resources/modules/logging-logback.mod b/jetty-home/src/main/resources/modules/logging-logback.mod new file mode 100644 index 00000000000..cdffd67921f --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-logback.mod @@ -0,0 +1,45 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure jetty logging to use Logback Logging. +SLF4J is used as the core logging mechanism. + +[tags] +logging + +[depends] +logging/slf4j +resources + +[provides] +logging + +[files] +basehome:modules/logging/logback +maven://ch.qos.logback/logback-classic/${logback.version}|lib/logging/logback-classic-${logback.version}.jar +maven://ch.qos.logback/logback-core/${logback.version}|lib/logging/logback-core-${logback.version}.jar + +[lib] +lib/logging/logback-classic-${logback.version}.jar +lib/logging/logback-core-${logback.version}.jar + +[ini] +logback.version?=1.3.0-alpha5 +jetty.webapp.addServerClasses+=,ch.qos.logback. + +[license] +Logback: the reliable, generic, fast and flexible logging framework. +Copyright (C) 1999-2012, QOS.ch. All rights reserved. + +This program and the accompanying materials are dual-licensed under +either: + + the terms of the Eclipse Public License v1.0 + as published by the Eclipse Foundation: + http://www.eclipse.org/legal/epl-v10.html + +or (per the licensee's choosing) under + + the terms of the GNU Lesser General Public License version 2.1 + as published by the Free Software Foundation: + http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html diff --git a/jetty-home/src/main/resources/modules/logging-noop.mod b/jetty-home/src/main/resources/modules/logging-noop.mod new file mode 100644 index 00000000000..2a8c3743c47 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging-noop.mod @@ -0,0 +1,13 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure logging to use SLF4J No-Op Implementation + +[tags] +logging + +[provides] +logging + +[depends] +logging/slf4j diff --git a/jetty-home/src/main/resources/modules/logging/jetty/resources/jetty-logging.properties b/jetty-home/src/main/resources/modules/logging/jetty/resources/jetty-logging.properties new file mode 100644 index 00000000000..d0fdf6c5bd5 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/jetty/resources/jetty-logging.properties @@ -0,0 +1,8 @@ +## Set logging levels from: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF +org.eclipse.jetty.LEVEL=INFO +## Configure a level for an arbitrary logger tree +#com.example.LEVEL=INFO +## Configure a level for specific logger +#com.example.MyComponent.LEVEL=INFO +## Hide stacks traces in an arbitrary logger tree +#com.example.STACKS=false diff --git a/jetty-home/src/main/resources/modules/logging/jul/resources/java-util-logging.properties b/jetty-home/src/main/resources/modules/logging/jul/resources/java-util-logging.properties new file mode 100644 index 00000000000..a09450fc280 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/jul/resources/java-util-logging.properties @@ -0,0 +1,13 @@ +.level=INFO +handlers=java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level=INFO +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +## Note: The java.util.logging.SimpleFormatter does NOT have the ability to display +## the Thread name of when the logging event occurred, this will make debugging difficult +## See https://stackoverflow.com/questions/6889057/printing-thread-name-using-java-util-logging +java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS [%4$s] (%3$s) - %5$s%6$s%n +#handlers = java.util.logging.FileHandler +#java.util.logging.FileHandler.pattern = ${jetty.logging.dir}/jetty%u.log +#java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter + + diff --git a/jetty-home/src/main/resources/modules/logging/log4j1/resources/log4j.xml b/jetty-home/src/main/resources/modules/logging/log4j1/resources/log4j.xml new file mode 100644 index 00000000000..b4bf0ae6994 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/log4j1/resources/log4j.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jetty-home/src/main/resources/modules/logging/log4j2/resources/log4j2.xml b/jetty-home/src/main/resources/modules/logging/log4j2/resources/log4j2.xml new file mode 100644 index 00000000000..f20a1d40515 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/log4j2/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jetty-home/src/main/resources/modules/logging/logback/resources/logback.xml b/jetty-home/src/main/resources/modules/logging/logback/resources/logback.xml new file mode 100644 index 00000000000..23a6dbc24da --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/logback/resources/logback.xml @@ -0,0 +1,11 @@ + + + + %d{HH:mm:ss.SSS} [%level] :%thread: \(%logger\) - %msg%n + + + + + + + \ No newline at end of file diff --git a/jetty-home/src/main/resources/modules/logging/slf4j.mod b/jetty-home/src/main/resources/modules/logging/slf4j.mod new file mode 100644 index 00000000000..67387a2c1f5 --- /dev/null +++ b/jetty-home/src/main/resources/modules/logging/slf4j.mod @@ -0,0 +1,18 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Configure logging to use slf4j with no impl +(If you don't select an impl, then NOP will be used by slf4j) + +[tags] +logging + +[provides] +slf4j + +[lib] +lib/logging/slf4j-api-${slf4j.version}.jar + +[ini] +slf4j.version?=2.0.0-alpha1 +jetty.webapp.addServerClasses+=,org.slf4j. diff --git a/jetty-http/src/main/java/module-info.java b/jetty-http/src/main/java/module-info.java index b606ff8b299..918c69b7735 100644 --- a/jetty-http/src/main/java/module-info.java +++ b/jetty-http/src/main/java/module-info.java @@ -25,6 +25,7 @@ module org.eclipse.jetty.http exports org.eclipse.jetty.http.pathmap; requires transitive org.eclipse.jetty.io; + requires org.slf4j; uses HttpFieldPreEncoder; diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java index ed2228997ee..b2109cabb0e 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java @@ -24,9 +24,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jetty.http.HttpParser.State; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.toolchain.test.Net; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; diff --git a/jetty-http/src/test/resources/jetty-logging.properties b/jetty-http/src/test/resources/jetty-logging.properties index 799aa62aed3..ab545e4ab63 100644 --- a/jetty-http/src/test/resources/jetty-logging.properties +++ b/jetty-http/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG #org.eclipse.jetty.http.LEVEL=DEBUG diff --git a/jetty-http2/http2-client/src/main/java/module-info.java b/jetty-http2/http2-client/src/main/java/module-info.java index dafdf57a310..721a1f43a8d 100644 --- a/jetty-http2/http2-client/src/main/java/module-info.java +++ b/jetty-http2/http2-client/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.http2.client requires org.eclipse.jetty.alpn.client; requires transitive org.eclipse.jetty.http2.common; + requires org.slf4j; } diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java index dbf003f06b8..2ec076e8b70 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java @@ -72,6 +72,7 @@ import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; import org.eclipse.jetty.io.AbstractEndPoint; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.WriteFlusher; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpOutput; @@ -85,7 +86,6 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; diff --git a/jetty-http2/http2-client/src/test/resources/jetty-logging.properties b/jetty-http2/http2-client/src/test/resources/jetty-logging.properties index 5304801a325..c94292482f0 100644 --- a/jetty-http2/http2-client/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-client/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.http2.LEVEL=DEBUG org.eclipse.jetty.http2.hpack.LEVEL=INFO diff --git a/jetty-http2/http2-common/src/main/java/module-info.java b/jetty-http2/http2-common/src/main/java/module-info.java index 27e60a4bd26..592d25f361e 100644 --- a/jetty-http2/http2-common/src/main/java/module-info.java +++ b/jetty-http2/http2-common/src/main/java/module-info.java @@ -26,4 +26,5 @@ module org.eclipse.jetty.http2.common exports org.eclipse.jetty.http2.parser; requires transitive org.eclipse.jetty.http2.hpack; + requires org.slf4j; } diff --git a/jetty-http2/http2-common/src/test/resources/jetty-logging.properties b/jetty-http2/http2-common/src/test/resources/jetty-logging.properties index b4e43807801..874ebdbc1eb 100644 --- a/jetty-http2/http2-common/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-common/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.http2.LEVEL=INFO diff --git a/jetty-http2/http2-hpack/src/main/java/module-info.java b/jetty-http2/http2-hpack/src/main/java/module-info.java index c482d5ea44f..53ae65a0873 100644 --- a/jetty-http2/http2-hpack/src/main/java/module-info.java +++ b/jetty-http2/http2-hpack/src/main/java/module-info.java @@ -24,6 +24,7 @@ module org.eclipse.jetty.http2.hpack exports org.eclipse.jetty.http2.hpack; requires transitive org.eclipse.jetty.http; + requires org.slf4j; provides HttpFieldPreEncoder with HpackFieldPreEncoder; } diff --git a/jetty-http2/http2-hpack/src/test/resources/jetty-logging.properties b/jetty-http2/http2-hpack/src/test/resources/jetty-logging.properties index f4e33644f4c..9c83a8ee8bb 100644 --- a/jetty-http2/http2-hpack/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-hpack/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.http2.LEVEL=DEBUG #org.eclipse.jetty.http2.hpack.LEVEL=DEBUG diff --git a/jetty-http2/http2-http-client-transport/src/main/java/module-info.java b/jetty-http2/http2-http-client-transport/src/main/java/module-info.java index bb53a46a7cd..c5e35ef3ef8 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/module-info.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/module-info.java @@ -23,4 +23,5 @@ module org.eclipse.jetty.http2.http.client.transport requires org.eclipse.jetty.alpn.client; requires transitive org.eclipse.jetty.client; requires transitive org.eclipse.jetty.http2.client; + requires org.slf4j; } diff --git a/jetty-http2/http2-http-client-transport/src/test/resources/jetty-logging.properties b/jetty-http2/http2-http-client-transport/src/test/resources/jetty-logging.properties index 34929219c9d..1cec8b3203e 100644 --- a/jetty-http2/http2-http-client-transport/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-http-client-transport/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.client.LEVEL=DEBUG org.eclipse.jetty.http2.hpack.LEVEL=INFO diff --git a/jetty-http2/http2-server/src/main/java/module-info.java b/jetty-http2/http2-server/src/main/java/module-info.java index 198e74749d5..4bce9a0b782 100644 --- a/jetty-http2/http2-server/src/main/java/module-info.java +++ b/jetty-http2/http2-server/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.http2.server requires transitive org.eclipse.jetty.http2.common; requires transitive org.eclipse.jetty.server; + requires org.slf4j; } diff --git a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java index b2d25039c88..650634fc2d9 100644 --- a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java +++ b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java @@ -60,12 +60,12 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ChannelEndPoint; import org.eclipse.jetty.io.ManagedSelector; import org.eclipse.jetty.io.SocketChannelEndPoint; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; diff --git a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties index 9611e7c6ad5..d71badfeed6 100644 --- a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.http2.LEVEL=DEBUG org.eclipse.jetty.http2.hpack.LEVEL=INFO diff --git a/jetty-io/src/main/java/module-info.java b/jetty-io/src/main/java/module-info.java index 7aee3271134..e9286fa962f 100644 --- a/jetty-io/src/main/java/module-info.java +++ b/jetty-io/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.io exports org.eclipse.jetty.io.ssl; requires transitive org.eclipse.jetty.util; + requires org.slf4j; } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java index cfb9b4634a8..c2fbc7f91ee 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java @@ -32,10 +32,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FutureCallback; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; diff --git a/jetty-io/src/test/resources/jetty-logging.properties b/jetty-io/src/test/resources/jetty-logging.properties index 0e7fd71dc25..a83221a9354 100644 --- a/jetty-io/src/test/resources/jetty-logging.properties +++ b/jetty-io/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.io.AbstractConnection.LEVEL=DEBUG #org.eclipse.jetty.io.ManagedSelector.LEVEL=DEBUG diff --git a/jetty-jaas/src/main/java/module-info.java b/jetty-jaas/src/main/java/module-info.java index 954880aa359..848615dea70 100644 --- a/jetty-jaas/src/main/java/module-info.java +++ b/jetty-jaas/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.jaas exports org.eclipse.jetty.jaas.spi; requires transitive org.eclipse.jetty.security; + requires org.slf4j; // Only required if using JDBCLoginModule. requires static java.sql; diff --git a/jetty-jaspi/src/main/java/module-info.java b/jetty-jaspi/src/main/java/module-info.java index 9db76bdd281..c24a9d13b12 100644 --- a/jetty-jaspi/src/main/java/module-info.java +++ b/jetty-jaspi/src/main/java/module-info.java @@ -28,6 +28,7 @@ module org.eclipse.jetty.security.jaspi requires javax.security.auth.message; requires jetty.servlet.api; requires transitive org.eclipse.jetty.security; + requires org.slf4j; provides Authenticator.Factory with JaspiAuthenticatorFactory; } diff --git a/jetty-jmx/src/main/java/module-info.java b/jetty-jmx/src/main/java/module-info.java index ac62f51dd98..8036a54102b 100644 --- a/jetty-jmx/src/main/java/module-info.java +++ b/jetty-jmx/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.jmx // Applications that use ObjectMBean must use JMX classes too. requires transitive java.management; requires transitive org.eclipse.jetty.util; + requires org.slf4j; // Only required if using ConnectorServer. requires static java.management.rmi; diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java deleted file mode 100644 index 48714ab0257..00000000000 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log.jmx; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jetty.jmx.ObjectMBean; -import org.eclipse.jetty.util.annotation.ManagedAttribute; -import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.annotation.ManagedOperation; -import org.eclipse.jetty.util.annotation.Name; -import org.eclipse.jetty.util.log.Log; - -/** - * - */ -@ManagedObject("Jetty Logging") -public class LogMBean extends ObjectMBean -{ - public LogMBean(Object managedObject) - { - super(managedObject); - } - - @ManagedAttribute(value = "list of instantiated loggers") - public List getLoggers() - { - List keySet = new ArrayList(Log.getLoggers().keySet()); - return keySet; - } - - @ManagedOperation(value = "true if debug enabled for the given logger") - public boolean isDebugEnabled(@Name("logger") String logger) - { - return Log.getLogger(logger).isDebugEnabled(); - } - - @ManagedOperation(value = "Set debug enabled for given logger") - public void setDebugEnabled(@Name("logger") String logger, @Name("enabled") Boolean enabled) - { - Log.getLogger(logger).setDebugEnabled(enabled); - } -} diff --git a/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/PojoTest.java b/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/PojoTest.java index 18e39cc1991..3f52ab9245c 100644 --- a/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/PojoTest.java +++ b/jetty-jmx/src/test/java/org/eclipse/jetty/jmx/PojoTest.java @@ -26,7 +26,6 @@ import com.openpojo.validation.Validator; import com.openpojo.validation.ValidatorBuilder; import com.openpojo.validation.test.impl.GetterTester; import com.openpojo.validation.test.impl.SetterTester; -import org.eclipse.jetty.util.log.jmx.LogMBean; import org.junit.jupiter.api.Test; /* @@ -38,7 +37,7 @@ public class PojoTest public void testOpenPojo() { Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()).build(); - List classes = Arrays.asList(MBeanContainer.class, ObjectMBean.class, LogMBean.class); + List classes = Arrays.asList(MBeanContainer.class, ObjectMBean.class); for (Class clazz : classes) { validator.validate(PojoClassFactory.getPojoClass(clazz)); diff --git a/jetty-jmx/src/test/java/org/eclipse/jetty/util/log/jmx/LogMBeanTest.java b/jetty-jmx/src/test/java/org/eclipse/jetty/util/log/jmx/LogMBeanTest.java deleted file mode 100644 index 90cfbf50893..00000000000 --- a/jetty-jmx/src/test/java/org/eclipse/jetty/util/log/jmx/LogMBeanTest.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log.jmx; - -import com.acme.Managed; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.in; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class LogMBeanTest -{ - - private Managed managed; - - private LogMBean logMBean; - - private static final String MANAGED_CLASS = "Managed"; - - @BeforeEach - public void setUp() - { - managed = new Managed(); - logMBean = new LogMBean(managed); - } - - @Test - public void testKeySet() - { - // given - assertThat("Managed is not registered with loggers", MANAGED_CLASS, not(is(in(logMBean.getLoggers())))); - - // when - logMBean.setDebugEnabled(MANAGED_CLASS, true); - - // then - assertThat("Managed must be registered with loggers", MANAGED_CLASS, is(in(logMBean.getLoggers()))); - assertTrue(logMBean.isDebugEnabled(MANAGED_CLASS), "This must return true as debug is enabled for this class"); - } -} diff --git a/jetty-jmx/src/test/resources/jetty-logging.properties b/jetty-jmx/src/test/resources/jetty-logging.properties index ad4b63c91cc..1f674758b1c 100644 --- a/jetty-jmx/src/test/resources/jetty-logging.properties +++ b/jetty-jmx/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.jmx.LEVEL=DEBUG diff --git a/jetty-jndi/src/main/java/module-info.java b/jetty-jndi/src/main/java/module-info.java index 2bbc61066ca..c5c5e41cb48 100644 --- a/jetty-jndi/src/main/java/module-info.java +++ b/jetty-jndi/src/main/java/module-info.java @@ -25,6 +25,7 @@ module org.eclipse.jetty.jndi requires transitive java.naming; requires transitive org.eclipse.jetty.server; + requires org.slf4j; // Only required if using DataSourceCloser. requires static java.sql; diff --git a/jetty-maven-plugin/pom.xml b/jetty-maven-plugin/pom.xml index e1a6c907e1e..131a3603827 100644 --- a/jetty-maven-plugin/pom.xml +++ b/jetty-maven-plugin/pom.xml @@ -236,6 +236,11 @@ apache-jstl ${project.version} + + org.slf4j + slf4j-api + ${slf4j.version} + jakarta.transaction jakarta.transaction-api @@ -259,9 +264,6 @@ org.apache.maven.plugins maven-project-info-reports-plugin - - false - diff --git a/jetty-maven-plugin/src/it/javax-annotation-api/pom.xml b/jetty-maven-plugin/src/it/javax-annotation-api/pom.xml index fc1dfce43cf..4d2af3f1b78 100644 --- a/jetty-maven-plugin/src/it/javax-annotation-api/pom.xml +++ b/jetty-maven-plugin/src/it/javax-annotation-api/pom.xml @@ -19,6 +19,7 @@ ${project.build.directory}/jetty-run-mojo-annotation.txt EMBED + 1.7.30 @@ -41,12 +42,17 @@ org.slf4j slf4j-api - @slf4j.version@ + ${logging.slf4j.version} - org.apache.logging.log4j - log4j-slf4j18-impl - @log4j2.version@ + org.slf4j + slf4j-log4j12 + ${logging.slf4j.version} + + + org.slf4j + jul-to-slf4j + ${logging.slf4j.version} org.springframework.boot @@ -87,9 +93,7 @@ ${jetty.port.file} - - ${basedir}/src/config/jetty.xml - + ${basedir}/src/config/jetty.xml diff --git a/jetty-maven-plugin/src/it/javax-annotation-api/src/main/resources/log4j.xml b/jetty-maven-plugin/src/it/javax-annotation-api/src/main/resources/log4j.xml new file mode 100644 index 00000000000..83a28a67537 --- /dev/null +++ b/jetty-maven-plugin/src/it/javax-annotation-api/src/main/resources/log4j.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java index 47ed26e235a..61f143ef172 100755 --- a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java @@ -20,7 +20,6 @@ package test; import java.net.URL; import java.net.URLClassLoader; - import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; diff --git a/jetty-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml b/jetty-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml index 4ece79123db..fe9829584d3 100644 --- a/jetty-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml +++ b/jetty-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,7 @@ - + - + greetServlet org.olamy.GreetingServiceImpl diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractForker.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractForker.java index 447e4a00641..7c544dace82 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractForker.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractForker.java @@ -23,8 +23,8 @@ import java.util.List; import java.util.Map; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * AbstractForker @@ -33,7 +33,7 @@ import org.eclipse.jetty.util.log.Logger; */ public abstract class AbstractForker extends AbstractLifeCycle { - private static final Logger LOG = Log.getLogger(AbstractForker.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractForker.class); protected Map env; @@ -245,7 +245,7 @@ public abstract class AbstractForker extends AbstractLifeCycle int attempts = maxChildStartChecks; while (!tokenFile.exists() && attempts > 0) { - Thread.currentThread().sleep(maxChildStartCheckMs); + Thread.sleep(maxChildStartCheckMs); --attempts; } if (attempts <= 0) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractWebAppMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractWebAppMojo.java index 91b61554a95..c4b1dd0b7df 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractWebAppMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractWebAppMojo.java @@ -680,7 +680,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo for (Object obj : pluginArtifacts) { Artifact artifact = (Artifact)obj; - if ("jar".equals(artifact.getType()) && !artifact.getGroupId().contains("slf4j")) + if ("jar".equals(artifact.getType())) { if (classPath.length() > 0) classPath.append(File.pathSeparator); @@ -689,7 +689,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo else { if (artifact.getArtifactId().equals(plugin.getArtifactId())) //get the jetty-maven-plugin jar - classPath.append(artifact.getFile().getAbsolutePath()); + classPath.append(artifact.getFile().getAbsolutePath()); } } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyForkedChild.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyForkedChild.java index 8f8190ea2fa..82885b8d336 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyForkedChild.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyForkedChild.java @@ -33,9 +33,9 @@ import org.eclipse.jetty.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher.PathWatchEvent; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * JettyForkedChild @@ -45,7 +45,7 @@ import org.eclipse.jetty.util.resource.Resource; */ public class JettyForkedChild extends AbstractLifeCycle { - private static final Logger LOG = Log.getLogger(JettyForkedChild.class); + private static final Logger LOG = LoggerFactory.getLogger(JettyForkedChild.class); protected JettyEmbedder jetty; protected File tokenFile; diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenMetaInfConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenMetaInfConfiguration.java index 447215decec..ac0175e77bb 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenMetaInfConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenMetaInfConfiguration.java @@ -23,12 +23,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * MavenWebInfConfiguration @@ -38,7 +38,7 @@ import org.eclipse.jetty.webapp.WebAppContext; */ public class MavenMetaInfConfiguration extends MetaInfConfiguration { - private static final Logger LOG = Log.getLogger(MavenMetaInfConfiguration.class); + private static final Logger LOG = LoggerFactory.getLogger(MavenMetaInfConfiguration.class); protected static int COUNTER = 0; diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java index 166e2edf3f6..6199d45a7d1 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenQuickStartConfiguration.java @@ -20,19 +20,19 @@ package org.eclipse.jetty.maven.plugin; import org.eclipse.jetty.quickstart.QuickStartConfiguration; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * MavenQuickStartConfiguration */ public class MavenQuickStartConfiguration extends QuickStartConfiguration { - private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class); + private static final Logger LOG = LoggerFactory.getLogger(QuickStartConfiguration.class); @Override public Class replaces() diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebAppContext.java index 6937850ae0d..7aae9d0b533 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebAppContext.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebAppContext.java @@ -37,14 +37,14 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletMapping; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollection; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * MavenWebAppContext @@ -56,7 +56,7 @@ import org.eclipse.jetty.webapp.WebAppContext; */ public class MavenWebAppContext extends WebAppContext { - private static final Logger LOG = Log.getLogger(MavenWebAppContext.class); + private static final Logger LOG = LoggerFactory.getLogger(MavenWebAppContext.class); private static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN = ".*/javax.servlet-[^/]*\\.jar$|.*/jetty-servlet-api-[^/]*\\.jar$|.*javax.servlet.jsp.jstl-[^/]*\\.jar|.*taglibs-standard-impl-.*\\.jar"; @@ -425,7 +425,7 @@ public class MavenWebAppContext extends WebAppContext } catch (IOException e) { - LOG.ignore(e); + LOG.trace("IGNORED", e); } } return resource; diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java index 6d7201923bb..80901607c94 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java @@ -20,12 +20,12 @@ package org.eclipse.jetty.maven.plugin; import java.io.File; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppClassLoader; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebInfConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * MavenWebInfConfiguration @@ -35,7 +35,7 @@ import org.eclipse.jetty.webapp.WebInfConfiguration; */ public class MavenWebInfConfiguration extends WebInfConfiguration { - private static final Logger LOG = Log.getLogger(MavenWebInfConfiguration.class); + private static final Logger LOG = LoggerFactory.getLogger(MavenWebInfConfiguration.class); public MavenWebInfConfiguration() { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java index cc74752e11d..41697a26218 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/SelectiveJarResource.java @@ -35,9 +35,9 @@ import org.codehaus.plexus.util.SelectorUtils; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.JarResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * SelectiveJarResource @@ -46,7 +46,7 @@ import org.eclipse.jetty.util.resource.JarResource; */ public class SelectiveJarResource extends JarResource { - private static final Logger LOG = Log.getLogger(SelectiveJarResource.class); + private static final Logger LOG = LoggerFactory.getLogger(SelectiveJarResource.class); /** * Default matches every resource. diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestForkedChild.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestForkedChild.java index 4a5e3cdba60..8696223f210 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestForkedChild.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestForkedChild.java @@ -42,11 +42,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test the JettyForkedChild class, which * is the main that is executed by jetty:run/start in mode FORKED. - * */ public class TestForkedChild { @@ -107,11 +107,14 @@ public class TestForkedChild testDir.mkdirs(); tmpDir = new File(testDir, "tmp"); webappPropsFile = new File(testDir, "webapp.props"); - - stopPort = Integer.valueOf(System.getProperty("stop.port")); + + String stopPortString = System.getProperty("stop.port"); + assertNotNull(stopPortString, "stop.port System property"); + stopPort = Integer.valueOf(stopPortString); jettyPortString = System.getProperty("jetty.port"); + assertNotNull(jettyPortString, "jetty.port System property"); jettyPort = Integer.valueOf(jettyPortString); - + Random random = new Random(); token = Long.toString(random.nextLong() ^ System.currentTimeMillis(), 36).toUpperCase(Locale.ENGLISH); tokenFile = testDir.toPath().resolve(token + ".txt").toFile(); diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java index d52c4da6857..0f220b1cf3e 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java @@ -33,10 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -/** - * - * - */ public class TestJettyEmbedder { @@ -82,7 +78,7 @@ public class TestJettyEmbedder MavenWebAppContext webApp = new MavenWebAppContext(); Server server = new Server(); Map jettyProperties = new HashMap<>(); - jettyProperties.put("jetty.server.dumpAfterStart", "true"); + jettyProperties.put("jetty.server.dumpAfterStart", "false"); ContextHandler otherHandler = new ContextHandler(); otherHandler.setContextPath("/other"); diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestWebAppPropertyConverter.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestWebAppPropertyConverter.java index 97291bafce5..9b238d2647f 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestWebAppPropertyConverter.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestWebAppPropertyConverter.java @@ -35,6 +35,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -152,7 +153,7 @@ public class TestWebAppPropertyConverter assertEquals(true, webApp.isPersistTempDirectory()); assertEquals(war.getAbsolutePath(), webApp.getWar()); assertEquals(webXml.getAbsolutePath(), webApp.getDescriptor()); - assertTrue(webApp.getBaseResource() instanceof ResourceCollection); + assertThat(webApp.getBaseResource(), instanceOf(ResourceCollection.class)); assertThat(webApp.getBaseResource().toString(), Matchers.containsString(Resource.newResource(base1).toString())); assertThat(webApp.getBaseResource().toString(), Matchers.containsString(Resource.newResource(base2).toString())); } diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/IntegrationTestGetContent.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/IntegrationTestGetContent.java index 03340d6391e..7ee511214ed 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/IntegrationTestGetContent.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/IntegrationTestGetContent.java @@ -75,7 +75,7 @@ public class IntegrationTestGetContent } String response = httpClient.GET(url).getContentAsString(); assertTrue(response.contains(contentCheck), "it test " + System.getProperty("maven.it.name") + - ", response not contentCheck: " + contentCheck + ", response:" + response); + ", response not contentCheck: " + contentCheck + ", response:" + response); System.out.println("contentCheck"); } if (Boolean.getBoolean("helloTestServlet")) @@ -104,8 +104,9 @@ public class IntegrationTestGetContent int attempts = 70; int port = -1; String s = System.getProperty("jetty.port.file"); - assertNotNull(s); + assertNotNull(s, "jetty.port.file System property"); Path p = Paths.get(s); + System.err.println("Looking for port file: " + p); while (true) { if (Files.exists(p)) @@ -127,8 +128,9 @@ public class IntegrationTestGetContent } else { - Thread.currentThread().sleep(1000); + Thread.sleep(1000); } + System.err.printf(" attempts left: #%d%n", attempts); } } return port; diff --git a/jetty-maven-plugin/src/test/resources/embedder-context.xml b/jetty-maven-plugin/src/test/resources/embedder-context.xml index f2c058e0fda..c13affca5e7 100644 --- a/jetty-maven-plugin/src/test/resources/embedder-context.xml +++ b/jetty-maven-plugin/src/test/resources/embedder-context.xml @@ -1,8 +1,6 @@ - - - /embedder - + + /embedder diff --git a/jetty-memcached/jetty-memcached-sessions/src/main/config/modules/sessions/session-data-cache/xmemcached.mod b/jetty-memcached/jetty-memcached-sessions/src/main/config/modules/sessions/session-data-cache/xmemcached.mod index 77a21ea759f..017c004f4b9 100644 --- a/jetty-memcached/jetty-memcached-sessions/src/main/config/modules/sessions/session-data-cache/xmemcached.mod +++ b/jetty-memcached/jetty-memcached-sessions/src/main/config/modules/sessions/session-data-cache/xmemcached.mod @@ -8,7 +8,7 @@ session [depends] session-store -slf4j-api +logging/slf4j [files] maven://com.googlecode.xmemcached/xmemcached/2.4.5|lib/xmemcached/xmemcached-2.4.5.jar diff --git a/jetty-openid/src/test/resources/jetty-logging.properties b/jetty-openid/src/test/resources/jetty-logging.properties index c73ac07f8ac..6f21b764f54 100755 --- a/jetty-openid/src/test/resources/jetty-logging.properties +++ b/jetty-openid/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.security.openid.LEVEL=DEBUG \ No newline at end of file diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java index ba0aa680755..a5b0022a065 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java @@ -37,7 +37,6 @@ import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.osgi.boot.OSGiServerConstants; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; @@ -132,6 +131,8 @@ public class TestOSGiUtil res.add(mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.bundle").versionAsInProject().start()); res.add(mavenBundle().groupId("jakarta.annotation").artifactId("jakarta.annotation-api").versionAsInProject().start()); res.add(mavenBundle().groupId("org.apache.geronimo.specs").artifactId("geronimo-jta_1.1_spec").version("1.1.1").start()); + res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject().noStart()); + res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-log4j12").versionAsInProject().noStart()); res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-util").versionAsInProject().start()); res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-deploy").versionAsInProject().start()); res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-server").versionAsInProject().start()); @@ -304,9 +305,7 @@ public class TestOSGiUtil options.add(mavenBundle().groupId("org.slf4j").artifactId("jul-to-slf4j").versionAsInProject().start()); options.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-log4j12").versionAsInProject().start()); options.add(mavenBundle().groupId("log4j").artifactId("log4j").versionAsInProject().start()); - options.add(systemProperty("org.eclipse.jetty.util.log.class").value(Slf4jLog.class.getName())); */ - options.add(systemProperty("org.eclipse.jetty.util.log.class").value(StdErrLog.class.getName())); options.add(systemProperty("org.eclipse.jetty.LEVEL").value("INFO")); return options; } diff --git a/jetty-plus/src/main/java/module-info.java b/jetty-plus/src/main/java/module-info.java index 3437b8fd765..0db6561deb0 100644 --- a/jetty-plus/src/main/java/module-info.java +++ b/jetty-plus/src/main/java/module-info.java @@ -29,6 +29,7 @@ module org.eclipse.jetty.plus requires org.eclipse.jetty.jndi; requires transitive org.eclipse.jetty.webapp; + requires org.slf4j; // Only required if using DataSourceLoginService. requires static java.sql; diff --git a/jetty-proxy/pom.xml b/jetty-proxy/pom.xml index d8964411ccd..0066877b80f 100644 --- a/jetty-proxy/pom.xml +++ b/jetty-proxy/pom.xml @@ -27,6 +27,10 @@ + + org.slf4j + slf4j-api + org.eclipse.jetty.toolchain jetty-servlet-api diff --git a/jetty-proxy/src/main/java/module-info.java b/jetty-proxy/src/main/java/module-info.java index 4f0b439c1dd..10a07fbc8eb 100644 --- a/jetty-proxy/src/main/java/module-info.java +++ b/jetty-proxy/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.proxy requires transitive org.eclipse.jetty.client; requires transitive org.eclipse.jetty.server; + requires transitive org.slf4j; } diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java index 002d5b3b7bd..19ce91ed7e1 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java @@ -51,9 +51,9 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.util.HttpCookieStore; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

Abstract base class for proxy servlets.

@@ -151,7 +151,7 @@ public abstract class AbstractProxyServlet extends HttpServlet catch (Exception x) { if (_log.isDebugEnabled()) - _log.debug(x); + _log.debug("Failed to stop client", x); } } @@ -208,7 +208,7 @@ public abstract class AbstractProxyServlet extends HttpServlet { servletName = getClass().getName() + "." + servletName; } - return Log.getLogger(servletName); + return LoggerFactory.getLogger(servletName); } /** @@ -692,14 +692,14 @@ public abstract class AbstractProxyServlet extends HttpServlet } catch (Exception e) { - _log.ignore(e); + _log.trace("IGNORED", e); try { proxyResponse.sendError(-1); } catch (Exception e2) { - _log.ignore(e2); + _log.trace("IGNORED", e2); } } finally diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java index da638db8941..0d153bafd92 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java @@ -332,7 +332,7 @@ public class ProxyServlet extends AbstractProxyServlet } catch (Throwable x) { - _log.ignore(x); + _log.trace("IGNORED", x); } } diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java index 6937aa50b5a..a77330e3765 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java @@ -61,6 +61,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.RuntimeIOException; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -75,7 +76,6 @@ import org.eclipse.jetty.util.Utf8StringBuilder; import org.eclipse.jetty.util.ajax.JSON; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Disabled; diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java index ac2d93a5f37..e226745bae3 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java @@ -43,6 +43,7 @@ import org.eclipse.jetty.client.util.BytesContentProvider; import org.eclipse.jetty.client.util.DeferredContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; @@ -50,7 +51,6 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-proxy/src/test/resources/jetty-logging.properties b/jetty-proxy/src/test/resources/jetty-logging.properties index af4d4f4fd55..7e7e5ce6384 100644 --- a/jetty-proxy/src/test/resources/jetty-logging.properties +++ b/jetty-proxy/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.proxy.LEVEL=DEBUG diff --git a/jetty-quickstart/src/main/java/module-info.java b/jetty-quickstart/src/main/java/module-info.java index d21970a7301..2bf0a15d606 100644 --- a/jetty-quickstart/src/main/java/module-info.java +++ b/jetty-quickstart/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.quickstart requires jetty.servlet.api; requires transitive org.eclipse.jetty.annotations; + requires org.slf4j; } diff --git a/jetty-rewrite/src/main/java/module-info.java b/jetty-rewrite/src/main/java/module-info.java index 685a4032f0f..7fa740254e8 100644 --- a/jetty-rewrite/src/main/java/module-info.java +++ b/jetty-rewrite/src/main/java/module-info.java @@ -23,4 +23,5 @@ module org.eclipse.jetty.rewrite requires jetty.servlet.api; requires transitive org.eclipse.jetty.server; + requires org.slf4j; } diff --git a/jetty-security/src/main/java/module-info.java b/jetty-security/src/main/java/module-info.java index bbb9d6fc4a7..06c20fccb8e 100644 --- a/jetty-security/src/main/java/module-info.java +++ b/jetty-security/src/main/java/module-info.java @@ -24,6 +24,7 @@ module org.eclipse.jetty.security exports org.eclipse.jetty.security.authentication; requires transitive org.eclipse.jetty.server; + requires org.slf4j; // Only required if using JDBCLoginService. requires static java.sql; diff --git a/jetty-security/src/test/resources/jetty-logging.properties b/jetty-security/src/test/resources/jetty-logging.properties index 24d5e3aadc7..e6d3c167d1f 100755 --- a/jetty-security/src/test/resources/jetty-logging.properties +++ b/jetty-security/src/test/resources/jetty-logging.properties @@ -1,6 +1,5 @@ # Setup default logging implementation for during testing -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog - +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.util.PathWatcher.LEVEL=DEBUG diff --git a/jetty-server/pom.xml b/jetty-server/pom.xml index af6e5b32e47..ceccb93e0f3 100644 --- a/jetty-server/pom.xml +++ b/jetty-server/pom.xml @@ -61,6 +61,10 @@ ${project.version} true
+ + org.slf4j + slf4j-api + org.eclipse.jetty diff --git a/jetty-server/src/main/config/modules/server.mod b/jetty-server/src/main/config/modules/server.mod index a6d85c7d5a4..6118e9abeac 100644 --- a/jetty-server/src/main/config/modules/server.mod +++ b/jetty-server/src/main/config/modules/server.mod @@ -7,11 +7,11 @@ Enables the core Jetty server on the classpath. jvm ext resources -logging [depend] threadpool bytebufferpool +logging [lib] lib/jetty-servlet-api-4.0.*.jar diff --git a/jetty-server/src/main/java/module-info.java b/jetty-server/src/main/java/module-info.java index 2c1a31d338a..3bba30e7b79 100644 --- a/jetty-server/src/main/java/module-info.java +++ b/jetty-server/src/main/java/module-info.java @@ -25,6 +25,7 @@ module org.eclipse.jetty.server exports org.eclipse.jetty.server.jmx to org.eclipse.jetty.jmx; exports org.eclipse.jetty.server.session; + requires transitive org.slf4j; requires transitive jetty.servlet.api; requires transitive org.eclipse.jetty.http; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Slf4jRequestLogWriter.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Slf4jRequestLogWriter.java index 9dfcc4bb1cf..e5faf948df7 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Slf4jRequestLogWriter.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Slf4jRequestLogWriter.java @@ -23,7 +23,7 @@ import java.io.IOException; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Slf4jLog; +import org.slf4j.LoggerFactory; /** * Request log writer using a Slf4jLog Logger @@ -31,7 +31,7 @@ import org.eclipse.jetty.util.log.Slf4jLog; @ManagedObject("Slf4j RequestLog Writer") public class Slf4jRequestLogWriter extends AbstractLifeCycle implements RequestLog.Writer { - private Slf4jLog logger; + private org.slf4j.Logger logger; private String loggerName; public Slf4jRequestLogWriter() @@ -65,7 +65,7 @@ public class Slf4jRequestLogWriter extends AbstractLifeCycle implements RequestL @Override protected synchronized void doStart() throws Exception { - logger = new Slf4jLog(loggerName); + logger = LoggerFactory.getLogger(loggerName); super.doStart(); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index fee184e224e..93b199cfc42 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -88,6 +88,7 @@ import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; +import org.slf4j.LoggerFactory; /** * ContextHandler. @@ -190,7 +191,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu private String[] _vhosts; // Host name portion, matching _vconnectors array private boolean[] _vhostswildcard; private String[] _vconnectors; // connector portion, matching _vhosts array - private Logger _logger; + private org.slf4j.Logger _logger; private boolean _allowNullPathInfo; private int _maxFormKeys = Integer.getInteger(MAX_FORM_KEYS_KEY, DEFAULT_MAX_FORM_KEYS); private int _maxFormContentSize = Integer.getInteger(MAX_FORM_CONTENT_SIZE_KEY, DEFAULT_MAX_FORM_CONTENT_SIZE); @@ -734,12 +735,12 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu } } - public Logger getLogger() + public org.slf4j.Logger getLogger() { return _logger; } - public void setLogger(Logger logger) + public void setLogger(org.slf4j.Logger logger) { _logger = logger; } @@ -753,7 +754,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu throw new IllegalStateException("Null contextPath"); if (_logger == null) - _logger = Log.getLogger(ContextHandler.class.getName() + getLogNameSuffix()); + _logger = LoggerFactory.getLogger(ContextHandler.class.getName() + getLogNameSuffix()); ClassLoader oldClassloader = null; Thread currentThread = null; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index d73c7b756f0..fd694f3276d 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -33,8 +33,8 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.tools.HttpTester; import org.eclipse.jetty.io.ArrayByteBufferPool; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index 25ab92ab85b..693dbf1bf02 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -37,11 +37,11 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.ssl.SslConnection; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ErrorHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ErrorHandlerTest.java index 263fcb372aa..b6335bf287d 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ErrorHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ErrorHandlerTest.java @@ -31,9 +31,9 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.BadMessageException; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.ajax.JSON; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index 972dcee7b73..d2acbc5c99c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -47,13 +47,12 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.LocalConnector.LocalEndPoint; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ErrorHandler; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -61,6 +60,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -72,6 +72,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpConnectionTest { + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(HttpConnectionTest.class); private Server server; private LocalConnector connector; @@ -1121,10 +1122,9 @@ public class HttpConnectionTest "\r\n" + "abcdefghij\r\n"; - Logger logger = Log.getLogger(HttpChannel.class); - try (StacklessLogging stackless = new StacklessLogging(logger)) + try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) { - logger.info("EXPECTING: java.lang.IllegalStateException..."); + LOG.info("EXPECTING: java.lang.IllegalStateException..."); String response = connector.getResponse(requests); offset = checkContains(response, offset, "HTTP/1.1 500"); offset = checkContains(response, offset, "Connection: close"); @@ -1246,11 +1246,10 @@ public class HttpConnectionTest }); server.start(); - Logger logger = Log.getLogger(HttpChannel.class); String response = null; - try (StacklessLogging stackless = new StacklessLogging(logger)) + try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) { - logger.info("Expect IOException: Response header too large..."); + LOG.info("Expect IOException: Response header too large..."); response = connector.getResponse("GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n" @@ -1313,7 +1312,7 @@ public class HttpConnectionTest public void testAsterisk() throws Exception { String response = null; - try (StacklessLogging stackless = new StacklessLogging(HttpParser.LOG)) + try (StacklessLogging stackless = new StacklessLogging(HttpParser.class)) { int offset = 0; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java index 4c355aac6da..3f9d323a90c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java @@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.tools.HttpTester; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java index 0d41ec5817d..bd2e83ce4fc 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java @@ -44,18 +44,19 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.tools.HttpTester; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.AbstractLogger; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledIfSystemProperty; import org.junit.jupiter.api.condition.DisabledOnJre; import org.junit.jupiter.api.condition.JRE; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -70,6 +71,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class HttpServerTestBase extends HttpServerTestFixture { + private static final Logger LOG = LoggerFactory.getLogger(HttpServerTestBase.class); private static final String REQUEST1_HEADER = "POST / HTTP/1.0\n" + "Host: localhost\n" + "Content-Type: text/xml; charset=utf-8\n" + @@ -1308,7 +1310,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()); StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) { - ((AbstractLogger)Log.getLogger(HttpChannel.class)).info("Expecting exception after commit then could not send 500...."); + LOG.info("Expecting exception after commit then could not send 500...."); OutputStream os = client.getOutputStream(); InputStream is = client.getInputStream(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java index 17d2e7adb30..a45a8d91be2 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java @@ -24,10 +24,10 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpParser; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.LocalConnector.LocalEndPoint; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java index e5ef9fda146..93bf04a133b 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ProxyConnectionTest.java @@ -24,10 +24,10 @@ import java.util.function.Consumer; import java.util.stream.Stream; import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.ErrorHandler; import org.eclipse.jetty.toolchain.test.Net; import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index 9ca079271ca..198392ae295 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -37,7 +37,6 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; - import javax.servlet.DispatcherType; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; @@ -53,6 +52,7 @@ import org.eclipse.jetty.http.HttpCompliance; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.LocalConnector.LocalEndPoint; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; @@ -63,7 +63,6 @@ import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java index d9485215956..11ce1879cc7 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java @@ -39,11 +39,11 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.SocketChannelEndPoint; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java index 465a7871a8b..0ec2c4ae857 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java @@ -31,10 +31,10 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java index 632cf7d5cd9..573e671035c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.BadMessageException; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.CustomRequestLog; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpChannel; @@ -45,7 +46,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.BlockingArrayQueue; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties index 21db0759fe3..407a732c85d 100644 --- a/jetty-server/src/test/resources/jetty-logging.properties +++ b/jetty-server/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG #org.eclipse.jetty.server.ConnectionLimit.LEVEL=DEBUG diff --git a/jetty-servlet/src/main/java/module-info.java b/jetty-servlet/src/main/java/module-info.java index 490efab586a..df68f9f4117 100644 --- a/jetty-servlet/src/main/java/module-info.java +++ b/jetty-servlet/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.servlet exports org.eclipse.jetty.servlet.listener; requires transitive org.eclipse.jetty.security; + requires org.slf4j; // Only required if using StatisticsServlet. requires static java.management; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java index 2a7cda734d4..23b3ad97101 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -43,7 +44,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java index 0d282e81d9e..ac16a759a6a 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java @@ -43,6 +43,7 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.DebugListener; import org.eclipse.jetty.server.HttpChannel; @@ -55,7 +56,6 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java index 09df044d2a1..a49ca551c1b 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java @@ -49,6 +49,7 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.ResourceContentFactory; @@ -61,7 +62,6 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.AfterEach; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java index 1b13cba102c..2e4452afcc0 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java @@ -47,6 +47,7 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; @@ -59,7 +60,6 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.UrlEncoded; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java index d576380ca5c..16136b68336 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java @@ -43,6 +43,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.BadMessageException; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpChannelState; @@ -51,7 +52,6 @@ import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/FilterHolderTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/FilterHolderTest.java index 9a69c9c34d6..57272790f22 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/FilterHolderTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/FilterHolderTest.java @@ -27,8 +27,8 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -45,15 +45,15 @@ public class FilterHolderTest public DummyFilter() { } - + @Override public void init(FilterConfig filterConfig) throws ServletException { } - + @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - { + { } } @@ -113,7 +113,7 @@ public class FilterHolderTest fh.initialize(); assertEquals(2, counter.get()); } - + @Test public void testCreateInstance() throws Exception { @@ -125,7 +125,7 @@ public class FilterHolderTest holder.setHeldClass(DummyFilter.class); Filter filter = holder.createInstance(); assertNotNull(filter); - + //test with a ServletContextHandler Server server = new Server(); ServletContextHandler context = new ServletContextHandler(); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ListenerHolderTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ListenerHolderTest.java index 0d2bc1b951f..b2c25bc1592 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ListenerHolderTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ListenerHolderTest.java @@ -20,8 +20,8 @@ package org.eclipse.jetty.servlet; import java.util.EventListener; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/MultiPartServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/MultiPartServletTest.java index 91d459d56d6..0189d82b908 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/MultiPartServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/MultiPartServletTest.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.client.util.MultiPartContentProvider; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.MimeTypes; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.MultiPartFormInputStream; import org.eclipse.jetty.server.Server; @@ -42,7 +43,6 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java index 5ece276371e..45786127a94 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java @@ -26,11 +26,11 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java index 50951d13bdd..d5149b00ece 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java @@ -60,6 +60,7 @@ import javax.servlet.http.HttpSessionIdListener; import javax.servlet.http.HttpSessionListener; import org.eclipse.jetty.http.pathmap.MappedResource; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.RoleInfo; import org.eclipse.jetty.security.SecurityHandler; @@ -80,14 +81,12 @@ import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.Decorator; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -725,7 +724,7 @@ public class ServletContextHandlerTest public void testAddServletFromServlet() throws Exception { //A servlet cannot be added by another servlet - Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); + Logger logger = LoggerFactory.getLogger(ContextHandler.class.getName() + "ROOT"); try (StacklessLogging stackless = new StacklessLogging(logger)) { @@ -754,7 +753,7 @@ public class ServletContextHandlerTest public void testAddFilterFromServlet() throws Exception { //A filter cannot be added from a servlet - Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); + Logger logger = LoggerFactory.getLogger(ContextHandler.class.getName() + "ROOT"); try (StacklessLogging stackless = new StacklessLogging(logger)) { @@ -783,7 +782,7 @@ public class ServletContextHandlerTest public void testAddServletByClassFromFilter() throws Exception { //A servlet cannot be added from a Filter - Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); + Logger logger = LoggerFactory.getLogger(ContextHandler.class.getName() + "ROOT"); try (StacklessLogging stackless = new StacklessLogging(logger)) { @@ -835,7 +834,7 @@ public class ServletContextHandlerTest public void testAddServletByInstanceFromFilter() throws Exception { //A servlet cannot be added from a Filter - Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); + Logger logger = LoggerFactory.getLogger(ContextHandler.class.getName() + "ROOT"); try (StacklessLogging stackless = new StacklessLogging(logger)) { @@ -887,7 +886,7 @@ public class ServletContextHandlerTest public void testAddServletByClassNameFromFilter() throws Exception { //A servlet cannot be added from a Filter - Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); + Logger logger = LoggerFactory.getLogger(ContextHandler.class.getName() + "ROOT"); try (StacklessLogging stackless = new StacklessLogging(logger)) { diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java index 6627dee8326..cf05efa8e9e 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java @@ -20,16 +20,15 @@ package org.eclipse.jetty.servlet; import java.util.Collections; import java.util.Set; - import javax.servlet.Servlet; import javax.servlet.ServletRegistration; import javax.servlet.UnavailableException; import javax.servlet.http.HttpServlet; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.MultiException; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -117,7 +116,7 @@ public class ServletHolderTest assertEquals("org.apache.jsp.a.b.c.blah_jsp", h.getClassNameForJsp("/a/b/c/blah.jsp")); assertEquals("org.apache.jsp.a.b.c.blah_jsp", h.getClassNameForJsp("a/b/c/blah.jsp")); } - + @Test public void testCreateInstance() throws Exception { @@ -129,7 +128,7 @@ public class ServletHolderTest holder.setHeldClass(FakeServlet.class); Servlet servlet = holder.createInstance(); assertNotNull(servlet); - + //test with a ServletContextHandler Server server = new Server(); ServletContextHandler context = new ServletContextHandler(); @@ -165,7 +164,7 @@ public class ServletHolderTest assertThat(e.getCause().getMessage(), containsString("foo")); } } - + @Test public void testWithClass() throws Exception { @@ -183,7 +182,7 @@ public class ServletHolderTest assertTrue(holder.isStarted()); } } - + @Test public void testWithClassName() throws Exception { @@ -199,7 +198,7 @@ public class ServletHolderTest handler.start(); assertTrue(holder.isAvailable()); assertTrue(holder.isStarted()); - } + } } @Test diff --git a/jetty-servlet/src/test/resources/jetty-logging.properties b/jetty-servlet/src/test/resources/jetty-logging.properties index 37f092141fc..821cf3d2f35 100644 --- a/jetty-servlet/src/test/resources/jetty-logging.properties +++ b/jetty-servlet/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=INFO #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG diff --git a/jetty-servlets/src/main/java/module-info.java b/jetty-servlets/src/main/java/module-info.java index 0f0c0ba254f..7457afe64c8 100644 --- a/jetty-servlets/src/main/java/module-info.java +++ b/jetty-servlets/src/main/java/module-info.java @@ -24,6 +24,7 @@ module org.eclipse.jetty.servlets exports org.eclipse.jetty.servlets; requires transitive jetty.servlet.api; + requires org.slf4j; // Only required if using CloseableDoSFilter. requires static org.eclipse.jetty.io; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ThreadStarvationTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ThreadStarvationTest.java index c21e12e0cd6..dd5db390cea 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ThreadStarvationTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ThreadStarvationTest.java @@ -48,6 +48,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.io.ChannelEndPoint; import org.eclipse.jetty.io.ManagedSelector; import org.eclipse.jetty.io.SocketChannelEndPoint; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; @@ -56,7 +57,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; diff --git a/jetty-servlets/src/test/resources/jetty-logging.properties b/jetty-servlets/src/test/resources/jetty-logging.properties index 3ceebb81afb..1e8385fcbd1 100644 --- a/jetty-servlets/src/test/resources/jetty-logging.properties +++ b/jetty-servlets/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.servlets.LEVEL=DEBUG #org.eclipse.jetty.servlet.ServletTester.LEVEL=DEBUG diff --git a/jetty-slf4j-impl/pom.xml b/jetty-slf4j-impl/pom.xml new file mode 100644 index 00000000000..aa59baac28b --- /dev/null +++ b/jetty-slf4j-impl/pom.xml @@ -0,0 +1,38 @@ + + + org.eclipse.jetty + jetty-project + 10.0.0-SNAPSHOT + + 4.0.0 + jetty-slf4j-impl + Jetty :: Slf4j Implementation + Slf4j Logging Implementation based on Jetty's older StdErrLog + http://www.eclipse.org/jetty + + ${project.groupId}.logging + + + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + org.slf4j + slf4j-api + + + diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/package-info.java b/jetty-slf4j-impl/src/main/java/module-info.java similarity index 72% rename from jetty-util/src/main/java/org/eclipse/jetty/util/log/package-info.java rename to jetty-slf4j-impl/src/main/java/module-info.java index 32e315704fa..0bfb99cd437 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/package-info.java +++ b/jetty-slf4j-impl/src/main/java/module-info.java @@ -16,8 +16,14 @@ // ======================================================================== // -/** - * Jetty Util : Common Logging Integrations - */ -package org.eclipse.jetty.util.log; +import org.eclipse.jetty.logging.JettyLoggingServiceProvider; +import org.slf4j.spi.SLF4JServiceProvider; +module org.eclipse.jetty.logging +{ + exports org.eclipse.jetty.logging; + + requires transitive org.slf4j; + + provides SLF4JServiceProvider with JettyLoggingServiceProvider; +} diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/package-info.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyAppender.java similarity index 74% rename from jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/package-info.java rename to jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyAppender.java index 47a281520e7..8aa65c21226 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/package-info.java +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyAppender.java @@ -16,8 +16,12 @@ // ======================================================================== // -/** - * Jetty JMX : Jetty Logging JMX Integration - */ -package org.eclipse.jetty.util.log.jmx; +package org.eclipse.jetty.logging; +import org.slf4j.event.Level; + +public interface JettyAppender +{ + void emit(JettyLogger logger, Level level, long timestamp, String threadName, + Throwable throwable, String message, Object... argumentArray); +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLogger.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLogger.java new file mode 100644 index 00000000000..90e1a639b5b --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLogger.java @@ -0,0 +1,678 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.util.Objects; + +import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.event.Level; +import org.slf4j.event.LoggingEvent; +import org.slf4j.helpers.SubstituteLogger; +import org.slf4j.spi.LocationAwareLogger; + +public class JettyLogger implements LocationAwareLogger, Logger +{ + /** + * The Level to set if you want this logger to be "OFF" + */ + public static final int OFF = 999; + /** + * The Level to set if you want this logger to show all events from all levels. + */ + public static final int ALL = -1; + + private final JettyLoggerFactory factory; + private final String name; + private final String condensedName; + private final JettyAppender appender; + private int level; + private boolean hideStacks = false; + + public JettyLogger(JettyLoggerFactory factory, String name, JettyAppender appender) + { + this(factory, name, appender, Level.INFO.toInt(), false); + } + + public JettyLogger(JettyLoggerFactory factory, String name, JettyAppender appender, int level, boolean hideStacks) + { + this.factory = factory; + this.name = name; + this.condensedName = JettyLoggerFactory.condensePackageString(name); + this.appender = appender; + this.level = level; + this.hideStacks = hideStacks; + } + + @Override + public void debug(String msg) + { + if (isDebugEnabled()) + { + emit(Level.DEBUG, msg); + } + } + + @Override + public void debug(String format, Object arg) + { + if (isDebugEnabled()) + { + emit(Level.DEBUG, format, arg); + } + } + + @Override + public void debug(String format, Object arg1, Object arg2) + { + if (isDebugEnabled()) + { + emit(Level.DEBUG, format, arg1, arg2); + } + } + + @Override + public void debug(String format, Object... arguments) + { + if (isDebugEnabled()) + { + emit(Level.DEBUG, format, arguments); + } + } + + @Override + public void debug(String msg, Throwable throwable) + { + if (isDebugEnabled()) + { + emit(Level.DEBUG, msg, throwable); + } + } + + @Override + public boolean isDebugEnabled(Marker marker) + { + return isDebugEnabled(); + } + + @Override + public void debug(Marker marker, String msg) + { + // TODO: do we want to support org.sfl4j.Marker? + debug(msg); + } + + @Override + public void debug(Marker marker, String format, Object arg) + { + // TODO: do we want to support org.sfl4j.Marker? + debug(format, arg); + } + + @Override + public void debug(Marker marker, String format, Object arg1, Object arg2) + { + // TODO: do we want to support org.sfl4j.Marker? + debug(format, arg1, arg2); + } + + @Override + public void debug(Marker marker, String format, Object... arguments) + { + // TODO: do we want to support org.sfl4j.Marker? + debug(format, arguments); + } + + @Override + public void debug(Marker marker, String msg, Throwable t) + { + // TODO: do we want to support org.sfl4j.Marker? + debug(msg, t); + } + + @Override + public void error(String msg) + { + if (isErrorEnabled()) + { + emit(Level.ERROR, msg); + } + } + + @Override + public void error(String format, Object arg) + { + if (isErrorEnabled()) + { + emit(Level.ERROR, format, arg); + } + } + + @Override + public void error(String format, Object arg1, Object arg2) + { + if (isErrorEnabled()) + { + emit(Level.ERROR, format, arg1, arg2); + } + } + + @Override + public void error(String format, Object... arguments) + { + if (isErrorEnabled()) + { + emit(Level.ERROR, format, arguments); + } + } + + @Override + public void error(String msg, Throwable throwable) + { + if (isErrorEnabled()) + { + emit(Level.ERROR, msg, throwable); + } + } + + @Override + public boolean isErrorEnabled(Marker marker) + { + return isErrorEnabled(); + } + + @Override + public void error(Marker marker, String msg) + { + // TODO: do we want to support org.sfl4j.Marker? + error(msg); + } + + @Override + public void error(Marker marker, String format, Object arg) + { + // TODO: do we want to support org.sfl4j.Marker? + error(format, arg); + } + + @Override + public void error(Marker marker, String format, Object arg1, Object arg2) + { + // TODO: do we want to support org.sfl4j.Marker? + error(format, arg1, arg2); + } + + @Override + public void error(Marker marker, String format, Object... arguments) + { + // TODO: do we want to support org.sfl4j.Marker? + error(format, arguments); + } + + @Override + public void error(Marker marker, String msg, Throwable t) + { + // TODO: do we want to support org.sfl4j.Marker? + error(msg, t); + } + + public JettyAppender getAppender() + { + return appender; + } + + /** + * Entry point for {@link LocationAwareLogger} + */ + @Override + public void log(Marker marker, String fqcn, int levelInt, String message, Object[] argArray, Throwable throwable) + { + if (this.level <= levelInt) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + getAppender().emit(this, intToLevel(levelInt), timestamp, threadName, throwable, message, argArray); + } + } + + /** + * Dynamic (via Reflection) entry point for {@link SubstituteLogger} usage. + * + * @param event the logging event + */ + @SuppressWarnings("unused") + public void log(LoggingEvent event) + { + // TODO: do we want to support org.sfl4j.Marker? + // TODO: do we want to support org.sfl4j.even.KeyValuePair? + getAppender().emit(this, event.getLevel(), event.getTimeStamp(), event.getThreadName(), event.getThrowable(), event.getMessage(), event.getArgumentArray()); + } + + public String getCondensedName() + { + return condensedName; + } + + public int getLevel() + { + return level; + } + + public void setLevel(Level level) + { + Objects.requireNonNull(level, "Level"); + setLevel(level.toInt()); + } + + public void setLevel(int lvlInt) + { + this.level = lvlInt; + + // apply setLevel to children too. + factory.walkChildLoggers(this.getName(), (logger) -> logger.setLevel(lvlInt)); + } + + @Override + public String getName() + { + return name; + } + + @Override + public void info(String msg) + { + if (isInfoEnabled()) + { + emit(Level.INFO, msg); + } + } + + @Override + public void info(String format, Object arg) + { + if (isInfoEnabled()) + { + emit(Level.INFO, format, arg); + } + } + + @Override + public void info(String format, Object arg1, Object arg2) + { + if (isInfoEnabled()) + { + emit(Level.INFO, format, arg1, arg2); + } + } + + @Override + public void info(String format, Object... arguments) + { + if (isInfoEnabled()) + { + emit(Level.INFO, format, arguments); + } + } + + @Override + public void info(String msg, Throwable throwable) + { + if (isInfoEnabled()) + { + emit(Level.INFO, msg, throwable); + } + } + + @Override + public boolean isInfoEnabled(Marker marker) + { + return isInfoEnabled(); + } + + @Override + public void info(Marker marker, String msg) + { + // TODO: do we want to support org.sfl4j.Marker? + info(msg); + } + + @Override + public void info(Marker marker, String format, Object arg) + { + // TODO: do we want to support org.sfl4j.Marker? + info(format, arg); + } + + @Override + public void info(Marker marker, String format, Object arg1, Object arg2) + { + // TODO: do we want to support org.sfl4j.Marker? + info(format, arg1, arg2); + } + + @Override + public void info(Marker marker, String format, Object... arguments) + { + // TODO: do we want to support org.sfl4j.Marker? + info(format, arguments); + } + + @Override + public void info(Marker marker, String msg, Throwable t) + { + // TODO: do we want to support org.sfl4j.Marker? + info(msg, t); + } + + @Override + public boolean isDebugEnabled() + { + return level <= Level.DEBUG.toInt(); + } + + @Override + public boolean isErrorEnabled() + { + return level <= Level.ERROR.toInt(); + } + + public boolean isHideStacks() + { + return hideStacks; + } + + public void setHideStacks(boolean hideStacks) + { + this.hideStacks = hideStacks; + + // apply setHideStacks to children too. + factory.walkChildLoggers(this.getName(), (logger) -> logger.setHideStacks(hideStacks)); + } + + @Override + public boolean isInfoEnabled() + { + return level <= Level.INFO.toInt(); + } + + @Override + public boolean isTraceEnabled() + { + return level <= Level.TRACE.toInt(); + } + + @Override + public boolean isWarnEnabled() + { + return level <= Level.WARN.toInt(); + } + + @Override + public void trace(String msg) + { + if (isTraceEnabled()) + { + emit(Level.TRACE, msg); + } + } + + @Override + public void trace(String format, Object arg) + { + if (isTraceEnabled()) + { + emit(Level.TRACE, format, arg); + } + } + + @Override + public void trace(String format, Object arg1, Object arg2) + { + if (isTraceEnabled()) + { + emit(Level.TRACE, format, arg1, arg2); + } + } + + @Override + public void trace(String format, Object... arguments) + { + if (isTraceEnabled()) + { + emit(Level.TRACE, format, arguments); + } + } + + @Override + public void trace(String msg, Throwable throwable) + { + if (isTraceEnabled()) + { + emit(Level.TRACE, msg, throwable); + } + } + + @Override + public boolean isTraceEnabled(Marker marker) + { + return isTraceEnabled(); + } + + @Override + public void trace(Marker marker, String msg) + { + // TODO: do we want to support org.sfl4j.Marker? + trace(msg); + } + + @Override + public void trace(Marker marker, String format, Object arg) + { + // TODO: do we want to support org.sfl4j.Marker? + trace(format, arg); + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) + { + // TODO: do we want to support org.sfl4j.Marker? + trace(format, arg1, arg2); + } + + @Override + public void trace(Marker marker, String format, Object... argArray) + { + // TODO: do we want to support org.sfl4j.Marker? + trace(format, argArray); + } + + @Override + public void trace(Marker marker, String msg, Throwable t) + { + // TODO: do we want to support org.sfl4j.Marker? + trace(msg, t); + } + + @Override + public void warn(String msg) + { + if (isWarnEnabled()) + { + emit(Level.WARN, msg); + } + } + + @Override + public void warn(String format, Object arg) + { + if (isWarnEnabled()) + { + emit(Level.WARN, format, arg); + } + } + + @Override + public void warn(String format, Object... arguments) + { + if (isWarnEnabled()) + { + emit(Level.WARN, format, arguments); + } + } + + @Override + public void warn(String format, Object arg1, Object arg2) + { + if (isWarnEnabled()) + { + emit(Level.WARN, format, arg1, arg2); + } + } + + @Override + public void warn(String msg, Throwable throwable) + { + if (isWarnEnabled()) + { + emit(Level.WARN, msg, throwable); + } + } + + @Override + public boolean isWarnEnabled(Marker marker) + { + return isWarnEnabled(); + } + + @Override + public void warn(Marker marker, String msg) + { + // TODO: do we want to support org.sfl4j.Marker? + warn(msg); + } + + @Override + public void warn(Marker marker, String format, Object arg) + { + // TODO: do we want to support org.sfl4j.Marker? + warn(format, arg); + } + + @Override + public void warn(Marker marker, String format, Object arg1, Object arg2) + { + // TODO: do we want to support org.sfl4j.Marker? + warn(format, arg1, arg2); + } + + @Override + public void warn(Marker marker, String format, Object... arguments) + { + // TODO: do we want to support org.sfl4j.Marker? + warn(format, arguments); + } + + @Override + public void warn(Marker marker, String msg, Throwable t) + { + // TODO: do we want to support org.sfl4j.Marker? + warn(msg, t); + } + + private void emit(Level level, String msg) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + getAppender().emit(this, level, timestamp, threadName, null, msg); + } + + private void emit(Level level, String format, Object arg) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + if (arg instanceof Throwable) + getAppender().emit(this, level, timestamp, threadName, (Throwable)arg, format); + else + getAppender().emit(this, level, timestamp, threadName, null, format, arg); + } + + private void emit(Level level, String format, Object arg1, Object arg2) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + if (arg2 instanceof Throwable) + getAppender().emit(this, level, timestamp, threadName, (Throwable)arg2, format, arg1); + else + getAppender().emit(this, level, timestamp, threadName, null, format, arg1, arg2); + } + + private void emit(Level level, String format, Object... arguments) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + getAppender().emit(this, level, timestamp, threadName, null, format, arguments); + } + + private void emit(Level level, String msg, Throwable throwable) + { + long timestamp = System.currentTimeMillis(); + String threadName = Thread.currentThread().getName(); + getAppender().emit(this, level, timestamp, threadName, throwable, msg); + } + + public static Level intToLevel(int level) + { + if (level >= JettyLogger.OFF) + return Level.ERROR; + if (level >= Level.ERROR.toInt()) + return Level.ERROR; + if (level >= Level.WARN.toInt()) + return Level.WARN; + if (level >= Level.INFO.toInt()) + return Level.INFO; + if (level >= Level.DEBUG.toInt()) + return Level.DEBUG; + if (level >= Level.TRACE.toInt()) + return Level.TRACE; + return Level.TRACE; // everything else + } + + public static String levelToString(int level) + { + if (level >= JettyLogger.OFF) + return "OFF"; + if (level >= Level.ERROR.toInt()) + return "ERROR"; + if (level >= Level.WARN.toInt()) + return "WARN"; + if (level >= Level.INFO.toInt()) + return "INFO"; + if (level >= Level.DEBUG.toInt()) + return "DEBUG"; + if (level >= Level.TRACE.toInt()) + return "TRACE"; + return "OFF"; // everything else + } + + @Override + public String toString() + { + return String.format("%s:%s:LEVEL=%s", JettyLogger.class.getSimpleName(), name, levelToString(level)); + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerConfiguration.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerConfiguration.java new file mode 100644 index 00000000000..2864430fee2 --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerConfiguration.java @@ -0,0 +1,332 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Locale; +import java.util.Properties; +import java.util.TimeZone; +import java.util.function.Function; + +import org.slf4j.event.Level; + +/** + * JettyLogger specific configuration: + *
    + *
  • {@code .LEVEL=(String:LevelName)}
  • + *
  • {@code .STACKS=(boolean)}
  • + *
+ */ +public class JettyLoggerConfiguration +{ + private static final int DEFAULT_LEVEL = Level.INFO.toInt(); + private static final boolean DEFAULT_HIDE_STACKS = false; + private static final String SUFFIX_LEVEL = ".LEVEL"; + private static final String SUFFIX_STACKS = ".STACKS"; + + private final Properties properties = new Properties(); + + /** + * Default JettyLogger configuration (empty) + */ + public JettyLoggerConfiguration() + { + } + + /** + * JettyLogger configuration from provided Properties + * + * @param props A set of properties to base this configuration off of + */ + public JettyLoggerConfiguration(Properties props) + { + load(props); + } + + public boolean getHideStacks(String name) + { + if (properties.isEmpty()) + return DEFAULT_HIDE_STACKS; + + String startName = name; + + // strip trailing dot + while (startName.endsWith(".")) + { + startName = startName.substring(0, startName.length() - 1); + } + + // strip ".STACKS" suffix (if present) + if (startName.endsWith(SUFFIX_STACKS)) + { + startName = startName.substring(0, startName.length() - SUFFIX_STACKS.length()); + } + + Boolean hideStacks = walkParentLoggerNames(startName, (key) -> + { + String stacksBool = properties.getProperty(key + SUFFIX_STACKS); + if (stacksBool != null) + { + return Boolean.parseBoolean(stacksBool); + } + return null; + }); + + if (hideStacks != null) + return hideStacks; + + return DEFAULT_HIDE_STACKS; + } + + /** + * Get the Logging Level for the provided log name. Using the FQCN first, then each package segment from longest to + * shortest. + * + * @param name the name to get log for + * @return the logging level int + */ + public int getLevel(String name) + { + if (properties.isEmpty()) + return DEFAULT_LEVEL; + + String startName = name != null ? name : ""; + + // strip trailing dot + while (startName.endsWith(".")) + { + startName = startName.substring(0, startName.length() - 1); + } + + // strip ".LEVEL" suffix (if present) + if (startName.endsWith(SUFFIX_LEVEL)) + { + startName = startName.substring(0, startName.length() - SUFFIX_LEVEL.length()); + } + + Integer level = walkParentLoggerNames(startName, (key) -> + { + String levelStr = properties.getProperty(key + SUFFIX_LEVEL); + if (levelStr != null) + { + return getLevelInt(key, levelStr); + } + return null; + }); + + if (level == null) + { + // try legacy root logging config + String levelStr = properties.getProperty("log" + SUFFIX_LEVEL); + if (levelStr != null) + { + level = getLevelInt("log", levelStr); + } + } + + if (level != null) + return level; + + return DEFAULT_LEVEL; + } + + public TimeZone getTimeZone(String key) + { + String zoneIdStr = properties.getProperty(key); + if (zoneIdStr == null) + return null; + + return TimeZone.getTimeZone(zoneIdStr); + } + + /** + * Load the Configuration from the ClassLoader + * + * @param loader the classloader to use when finding the {@code jetty-logging.properties} resources in. + * Passing {@code null} means the {@link ClassLoader#getSystemClassLoader()} is used. + * @return the configuration + */ + public JettyLoggerConfiguration load(ClassLoader loader) + { + return AccessController.doPrivileged((PrivilegedAction)() -> + { + // First see if the jetty-logging.properties object exists in the classpath. + // * This is an optional feature used by embedded mode use, and test cases to allow for early + // * configuration of the Log class in situations where access to the System.properties are + // * either too late or just impossible. + load(readProperties(loader, "jetty-logging.properties")); + + // Next see if an OS specific jetty-logging.properties object exists in the classpath. + // This really for setting up test specific logging behavior based on OS. + String osName = System.getProperty("os.name"); + if (osName != null && osName.length() > 0) + { + // NOTE: cannot use jetty-util's StringUtil.replace() as it may initialize logging itself. + osName = osName.toLowerCase(Locale.ENGLISH).replace(' ', '-'); + load(readProperties(loader, "jetty-logging-" + osName + ".properties")); + } + + // Now load the System.properties as-is into the properties, + // these values will override any key conflicts in properties. + load(System.getProperties()); + return this; + }); + } + + public boolean getBoolean(String key, boolean defValue) + { + String val = properties.getProperty(key, Boolean.toString(defValue)); + return Boolean.parseBoolean(val); + } + + public int getInt(String key, int defValue) + { + String val = properties.getProperty(key, Integer.toString(defValue)); + if (val == null) + { + return defValue; + } + try + { + return Integer.parseInt(val); + } + catch (NumberFormatException e) + { + return defValue; + } + } + + private Integer getLevelInt(String levelSegment, String levelStr) + { + if (levelStr == null) + { + return null; + } + + String levelName = levelStr.trim().toUpperCase(Locale.ENGLISH); + switch (levelName) + { + case "ALL": + return JettyLogger.ALL; + case "TRACE": + return Level.TRACE.toInt(); + case "DEBUG": + return Level.DEBUG.toInt(); + case "INFO": + return Level.INFO.toInt(); + case "WARN": + return Level.WARN.toInt(); + case "ERROR": + return Level.ERROR.toInt(); + case "OFF": + return JettyLogger.OFF; + default: + System.err.println("Unknown JettyLogger/Slf4J Level [" + levelSegment + "]=[" + levelName + "], expecting only [ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF] as values."); + return null; + } + } + + private URL getResource(ClassLoader loader, String resourceName) + { + if (loader == null) + { + return ClassLoader.getSystemResource(resourceName); + } + else + { + return loader.getResource(resourceName); + } + } + + /** + * Overlay existing properties with provided properties. + * + * @param props the properties to load + */ + private void load(Properties props) + { + if (props == null) + return; + + for (String name : props.stringPropertyNames()) + { + if (name.startsWith("org.eclipse.jetty.logging.") || + name.endsWith(".LEVEL") || + name.endsWith(".STACKS")) + { + String val = props.getProperty(name); + // Protect against application code insertion of non-String values (returned as null). + if (val != null) + properties.setProperty(name, val); + } + } + } + + private Properties readProperties(ClassLoader loader, String resourceName) + { + URL propsUrl = getResource(loader, resourceName); + if (propsUrl == null) + { + return null; + } + + try (InputStream in = propsUrl.openStream()) + { + Properties p = new Properties(); + p.load(in); + return p; + } + catch (IOException e) + { + System.err.println("[WARN] Error loading logging config: " + propsUrl); + e.printStackTrace(); + } + return null; + } + + private T walkParentLoggerNames(String startName, Function nameFunction) + { + String nameSegment = startName; + + // Checking with FQCN first, then each package segment from longest to shortest. + while ((nameSegment != null) && (nameSegment.length() > 0)) + { + T ret = nameFunction.apply(nameSegment); + if (ret != null) + return ret; + + // Trim and try again. + int idx = nameSegment.lastIndexOf('.'); + if (idx >= 0) + { + nameSegment = nameSegment.substring(0, idx); + } + else + { + nameSegment = null; + } + } + + return null; + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java new file mode 100644 index 00000000000..83d39cf71c1 --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java @@ -0,0 +1,182 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Consumer; + +import org.slf4j.ILoggerFactory; +import org.slf4j.Logger; + +public class JettyLoggerFactory implements ILoggerFactory +{ + private static final String ROOT_LOGGER_NAME = ""; + private final JettyLoggerConfiguration configuration; + private final JettyLogger rootLogger; + private ConcurrentMap loggerMap; + + public JettyLoggerFactory(JettyLoggerConfiguration config) + { + configuration = Objects.requireNonNull(config, "JettyLoggerConfiguration"); + + loggerMap = new ConcurrentHashMap<>(); + + StdErrAppender appender = new StdErrAppender(configuration); + + rootLogger = new JettyLogger(this, ROOT_LOGGER_NAME, appender); + loggerMap.put(ROOT_LOGGER_NAME, rootLogger); + rootLogger.setLevel(configuration.getLevel(ROOT_LOGGER_NAME)); + } + + /** + * Get a {@link JettyLogger} instance, creating if not yet existing. + * + * @param name the name of the logger + * @return the JettyLogger instance + */ + public JettyLogger getJettyLogger(String name) + { + if (name.equals(ROOT_LOGGER_NAME)) + { + return getRootLogger(); + } + + return loggerMap.computeIfAbsent(name, this::createLogger); + } + + /** + * Main interface for {@link ILoggerFactory} + * + * @param name the name of the logger + * @return the Slf4j Logger + */ + @Override + public Logger getLogger(String name) + { + return getJettyLogger(name); + } + + protected void walkChildLoggers(String parentName, Consumer childConsumer) + { + String prefix = parentName; + if (parentName.length() > 0 && !prefix.endsWith(".")) + { + prefix += "."; + } + + for (JettyLogger logger : loggerMap.values()) + { + if (logger.getName().equals(parentName)) + { + // skip self + continue; + } + + // is child, and is not itself + if (logger.getName().startsWith(prefix)) + { + childConsumer.accept(logger); + } + } + } + + public JettyLogger getRootLogger() + { + return rootLogger; + } + + private JettyLogger createLogger(String name) + { + // or is that handled by slf4j itself? + JettyAppender appender = rootLogger.getAppender(); + int level = this.configuration.getLevel(name); + boolean hideStacks = this.configuration.getHideStacks(name); + return new JettyLogger(this, name, appender, level, hideStacks); + } + + /** + * Condenses a classname by stripping down the package name to just the first character of each package name + * segment.Configured + * + *
+     * Examples:
+     * "org.eclipse.jetty.test.FooTest"           = "oejt.FooTest"
+     * "org.eclipse.jetty.server.logging.LogTest" = "orjsl.LogTest"
+     * 
+ * + * @param classname the fully qualified class name + * @return the condensed name + */ + protected static String condensePackageString(String classname) + { + if (classname == null || classname.isEmpty()) + { + return ""; + } + + int rawLen = classname.length(); + StringBuilder dense = new StringBuilder(rawLen); + boolean foundStart = false; + boolean hasPackage = false; + int startIdx = -1; + int endIdx = -1; + for (int i = 0; i < rawLen; i++) + { + char c = classname.charAt(i); + if (!foundStart) + { + foundStart = Character.isJavaIdentifierStart(c); + if (foundStart) + { + if (startIdx >= 0) + { + dense.append(classname.charAt(startIdx)); + hasPackage = true; + } + startIdx = i; + } + } + + if (foundStart) + { + if (!Character.isJavaIdentifierPart(c)) + { + foundStart = false; + } + else + { + endIdx = i; + } + } + } + // append remaining from startIdx + if ((startIdx >= 0) && (endIdx >= startIdx)) + { + if (hasPackage) + { + dense.append('.'); + } + dense.append(classname, startIdx, endIdx + 1); + } + + return dense.toString(); + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggingServiceProvider.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggingServiceProvider.java new file mode 100644 index 00000000000..01ad473162a --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggingServiceProvider.java @@ -0,0 +1,78 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import org.slf4j.ILoggerFactory; +import org.slf4j.IMarkerFactory; +import org.slf4j.helpers.BasicMarkerFactory; +import org.slf4j.helpers.NOPMDCAdapter; +import org.slf4j.spi.MDCAdapter; +import org.slf4j.spi.SLF4JServiceProvider; + +public class JettyLoggingServiceProvider implements SLF4JServiceProvider +{ + /** + * Declare the version of the SLF4J API this implementation is compiled against. + * The value of this field is modified with each major release. + */ + // to avoid constant folding by the compiler, this field must *not* be final + public static String REQUESTED_API_VERSION = "1.8.99"; // !final + + private JettyLoggerFactory loggerFactory; + private BasicMarkerFactory markerFactory; + private MDCAdapter mdcAdapter; + + @Override + public void initialize() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration().load(this.getClass().getClassLoader()); + loggerFactory = new JettyLoggerFactory(config); + markerFactory = new BasicMarkerFactory(); + mdcAdapter = new NOPMDCAdapter(); // TODO: Provide Jetty Implementation? + } + + public JettyLoggerFactory getJettyLoggerFactory() + { + return loggerFactory; + } + + @Override + public ILoggerFactory getLoggerFactory() + { + return getJettyLoggerFactory(); + } + + @Override + public IMarkerFactory getMarkerFactory() + { + return markerFactory; + } + + @Override + public MDCAdapter getMDCAdapter() + { + return mdcAdapter; + } + + @Override + public String getRequesteApiVersion() + { + return REQUESTED_API_VERSION; + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StacklessLogging.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StacklessLogging.java new file mode 100644 index 00000000000..93e05101ab1 --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StacklessLogging.java @@ -0,0 +1,123 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.util.HashSet; +import java.util.Set; + +import org.slf4j.ILoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A try-with-resources compatible layer for {@link JettyLogger#setHideStacks(boolean) hiding stacktraces} within the scope of the try block when + * logging with {@link JettyLogger} implementation. + *

+ * Use of other logging implementation cause no effect when using this class + *

+ * Example: + * + *

+ * try (StacklessLogging scope = new StacklessLogging(EventDriver.class,Noisy.class))
+ * {
+ *     doActionThatCausesStackTraces();
+ * }
+ * 
+ */ +public class StacklessLogging implements AutoCloseable +{ + private static final Logger LOG = LoggerFactory.getLogger(StacklessLogging.class); + private static final JettyLoggerFactory loggerFactory; + + static + { + JettyLoggerFactory jettyLoggerFactory = null; + ILoggerFactory activeLoggerFactory = LoggerFactory.getILoggerFactory(); + if (activeLoggerFactory instanceof JettyLoggerFactory) + { + jettyLoggerFactory = (JettyLoggerFactory)activeLoggerFactory; + } + else + { + LOG.warn("Unable to squelch stacktraces ({} is not a {})", + activeLoggerFactory.getClass().getName(), + JettyLoggerFactory.class.getName()); + } + loggerFactory = jettyLoggerFactory; + } + + private final Set squelched = new HashSet<>(); + + public StacklessLogging(Class... classesToSquelch) + { + for (Class clazz : classesToSquelch) + { + JettyLogger jettyLogger = loggerFactory.getJettyLogger(clazz.getName()); + if (!jettyLogger.isDebugEnabled()) + { + if (!jettyLogger.isHideStacks()) + { + jettyLogger.setHideStacks(true); + squelched.add(jettyLogger); + } + } + } + } + + public StacklessLogging(Package... packagesToSquelch) + { + for (Package pkg : packagesToSquelch) + { + JettyLogger jettyLogger = loggerFactory.getJettyLogger(pkg.getName()); + if (!jettyLogger.isDebugEnabled()) + { + if (!jettyLogger.isHideStacks()) + { + jettyLogger.setHideStacks(true); + squelched.add(jettyLogger); + } + } + } + } + + public StacklessLogging(Logger... logs) + { + for (Logger log : logs) + { + if (log instanceof JettyLogger && !log.isDebugEnabled()) + { + JettyLogger jettyLogger = ((JettyLogger)log); + if (!jettyLogger.isHideStacks()) + { + jettyLogger.setHideStacks(true); + squelched.add(jettyLogger); + } + } + } + } + + @Override + public void close() + { + for (JettyLogger log : squelched) + { + log.setHideStacks(false); + } + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java new file mode 100644 index 00000000000..001a3055461 --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java @@ -0,0 +1,255 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.io.PrintStream; +import java.util.Objects; +import java.util.TimeZone; + +import org.slf4j.event.Level; +import org.slf4j.helpers.FormattingTuple; +import org.slf4j.helpers.MessageFormatter; + +public class StdErrAppender implements JettyAppender +{ + /** + * Configuration keys specific to the StdErrAppender + */ + static final String NAME_CONDENSE_KEY = "org.eclipse.jetty.logging.appender.NAME_CONDENSE"; + static final String THREAD_PADDING_KEY = "org.eclipse.jetty.logging.appender.THREAD_PADDING"; + static final String MESSAGE_ESCAPE_KEY = "org.eclipse.jetty.logging.appender.MESSAGE_ESCAPE"; + static final String ZONEID_KEY = "org.eclipse.jetty.logging.appender.ZONE_ID"; + private static final String EOL = System.lineSeparator(); + + private final Timestamp timestamper; + + /** + * True to have output show condensed logger names, false to use the as defined long names. + */ + private final boolean condensedNames; + + /** + * True to have messages escaped for control characters, false to leave messages alone. + */ + private final boolean escapedMessages; + + /** + * The fixed size of the thread name to use for output + */ + private final int threadPadding; + + /** + * The stream to write logging events to. + */ + private PrintStream stderr; + + public StdErrAppender(JettyLoggerConfiguration config) + { + this(config, System.err); + } + + public StdErrAppender(JettyLoggerConfiguration config, PrintStream stream) + { + this(config, stream, null); + } + + public StdErrAppender(JettyLoggerConfiguration config, PrintStream stream, TimeZone timeZone) + { + Objects.requireNonNull(config, "JettyLoggerConfiguration"); + this.stderr = Objects.requireNonNull(stream, "PrintStream"); + + TimeZone tzone = timeZone; + if (tzone == null) + { + tzone = config.getTimeZone(ZONEID_KEY); + if (tzone == null) + { + tzone = TimeZone.getDefault(); + } + } + + this.timestamper = new Timestamp(tzone); + + this.condensedNames = config.getBoolean(NAME_CONDENSE_KEY, true); + this.escapedMessages = config.getBoolean(MESSAGE_ESCAPE_KEY, true); + this.threadPadding = config.getInt(THREAD_PADDING_KEY, -1); + } + + @Override + public void emit(JettyLogger logger, Level level, long timestamp, String threadName, Throwable throwable, String message, Object... argumentArray) + { + StringBuilder builder = new StringBuilder(64); + format(builder, logger, level, timestamp, threadName, throwable, message, argumentArray); + stderr.println(builder); + } + + public boolean isCondensedNames() + { + return condensedNames; + } + + public boolean isEscapedMessages() + { + return escapedMessages; + } + + public int getThreadPadding() + { + return threadPadding; + } + + public PrintStream getStream() + { + return stderr; + } + + public void setStream(PrintStream stream) + { + this.stderr = stream; + } + + private void format(StringBuilder builder, JettyLogger logger, Level level, long timestamp, String threadName, Throwable throwable, String message, Object... argumentArray) + { + Throwable cause = throwable; + + // Timestamp + timestamper.formatNow(timestamp, builder); + + // Level + builder.append(':').append(renderedLevel(level)); + + // Logger Name + builder.append(':'); + if (condensedNames) + { + builder.append(logger.getCondensedName()); + } + else + { + builder.append(logger.getName()); + } + + // Thread Name + builder.append(':'); + builder.append(threadName); // TODO: support TAG_PAD configuration + builder.append(':'); + + // Message + builder.append(' '); + + FormattingTuple ft = MessageFormatter.arrayFormat(message, argumentArray); + appendEscaped(builder, ft.getMessage()); + if (cause == null) + { + cause = ft.getThrowable(); + } + + // Throwable + if (cause != null) + { + if (logger.isHideStacks()) + { + builder.append(": ").append(cause); + } + else + { + appendCause(builder, cause, ""); + } + } + } + + private String renderedLevel(Level level) + { + switch (level) + { + case ERROR: // New for Jetty 10+ + return "ERROR"; + case WARN: + return "WARN "; + case INFO: + return "INFO "; + case DEBUG: + return "DEBUG"; + case TRACE: // New for Jetty 10+ + return "TRACE"; + default: + return "UNKNOWN"; + } + } + + private void appendCause(StringBuilder builder, Throwable cause, String indent) + { + builder.append(EOL).append(indent); + appendEscaped(builder, cause.toString()); + StackTraceElement[] elements = cause.getStackTrace(); + for (int i = 0; elements != null && i < elements.length; i++) + { + builder.append(EOL).append(indent).append("\tat "); + appendEscaped(builder, elements[i].toString()); + } + + for (Throwable suppressed : cause.getSuppressed()) + { + builder.append(EOL).append(indent).append("Suppressed: "); + appendCause(builder, suppressed, "\t|" + indent); + } + + Throwable by = cause.getCause(); + if (by != null && by != cause) + { + builder.append(EOL).append(indent).append("Caused by: "); + appendCause(builder, by, indent); + } + } + + private void appendEscaped(StringBuilder builder, String str) + { + if (str == null) + return; + + if (escapedMessages) + { + for (int i = 0; i < str.length(); ++i) + { + char c = str.charAt(i); + if (Character.isISOControl(c)) + { + if (c == '\n') + { + builder.append('|'); + } + else if (c == '\r') + { + builder.append('<'); + } + else + { + builder.append('?'); + } + } + else + { + builder.append(c); + } + } + } + else + builder.append(str); + } +} diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/Timestamp.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/Timestamp.java new file mode 100644 index 00000000000..064565d7c57 --- /dev/null +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/Timestamp.java @@ -0,0 +1,118 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.TimeZone; + +/** + *

+ * This is a super stripped down version of {@code DateCache} from jetty-util. + *

+ * + *

+ * This is a private class, only 1 method is exposed. {@link #formatNow(long, StringBuilder)}, + * Caching of the formatted timestamp up to the current second is still performed. + * Format updates the StringBuilder directly. + * And millisecond formatting is done by this class. + *

+ */ +class Timestamp +{ + private final DateTimeFormatter tzFormatter; + private final ZoneId zoneId; + private volatile Tick tick; + + public static class Tick + { + private final long seconds; + private final String formattedString; + + public Tick(long seconds, String string) + { + this.seconds = seconds; + formattedString = string; + } + } + + public Timestamp(TimeZone timeZone) + { + tzFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + zoneId = timeZone.toZoneId(); + tzFormatter.withZone(zoneId); + tick = null; + } + + /** + * Format a timestamp according to our stored formatter. + * The passed time is expected to be close to the current time, so it is + * compared to the last value passed and if it is within the same second, + * the format is reused. Otherwise a new cached format is created. + * + * @param now the milliseconds since unix epoch + */ + public void formatNow(long now, StringBuilder builder) + { + long seconds = now / 1000; + int ms = (int)(now % 1000); + + Tick tick = this.tick; + + // Is this the cached time + if (tick != null && tick.seconds == seconds) + { + builder.append(tick.formattedString); + } + else + { + formatTick(now, builder); + } + + if (ms > 99) + { + builder.append('.'); + } + else if (ms > 9) + { + builder.append(".0"); + } + else + { + builder.append(".00"); + } + builder.append(ms); + } + + protected void formatTick(long now, StringBuilder builder) + { + long seconds = now / 1000; + + Tick tick = this.tick; + // recheck the tick, to save multiple formats + if (tick == null || tick.seconds != seconds) + { + String s = ZonedDateTime.ofInstant(Instant.ofEpochMilli(now), zoneId).format(tzFormatter); + builder.append(s); + this.tick = new Tick(seconds, s); + } + } +} diff --git a/jetty-slf4j-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider b/jetty-slf4j-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider new file mode 100644 index 00000000000..f5ceffeaa2b --- /dev/null +++ b/jetty-slf4j-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider @@ -0,0 +1 @@ +org.eclipse.jetty.logging.JettyLoggingServiceProvider diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/CapturedStream.java similarity index 74% rename from jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java rename to jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/CapturedStream.java index f2404feb299..09b5814b1eb 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/CapturedStream.java @@ -16,47 +16,34 @@ // ======================================================================== // -package org.eclipse.jetty.util.log; +package org.eclipse.jetty.logging; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -public class StdErrCapture +public class CapturedStream extends PrintStream { - private ByteArrayOutputStream test; - private PrintStream err; + private final ByteArrayOutputStream test; - public StdErrCapture(StdErrLog log) + public CapturedStream() { - this(); - log.setStdErrStream(err); - } - - public StdErrCapture() - { - test = new ByteArrayOutputStream(); - err = new PrintStream(test); - } - - public void capture(StdErrLog log) - { - log.setStdErrStream(err); + super(new ByteArrayOutputStream(), true, UTF_8); + test = (ByteArrayOutputStream)super.out; } public void assertContains(String expectedString) { - err.flush(); String output = new String(test.toByteArray()); assertThat(output, containsString(expectedString)); } public void assertNotContains(String unexpectedString) { - err.flush(); String output = new String(test.toByteArray()); assertThat(output, not(containsString(unexpectedString))); } @@ -64,7 +51,6 @@ public class StdErrCapture @Override public String toString() { - err.flush(); return new String(test.toByteArray()); } } diff --git a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerConfigurationTest.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerConfigurationTest.java new file mode 100644 index 00000000000..bc3982c0c64 --- /dev/null +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerConfigurationTest.java @@ -0,0 +1,264 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.util.Properties; + +import org.junit.jupiter.api.Test; +import org.slf4j.event.Level; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JettyLoggerConfigurationTest +{ + @Test + public void testConfig() + { + Properties props = new Properties(); + props.setProperty(StdErrAppender.MESSAGE_ESCAPE_KEY, "false"); + props.setProperty(StdErrAppender.NAME_CONDENSE_KEY, "false"); + props.setProperty(StdErrAppender.THREAD_PADDING_KEY, "10"); + props.setProperty("com.mortbay.LEVEL", "WARN"); + props.setProperty("com.mortbay.STACKS", "false"); + + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + StdErrAppender appender = new StdErrAppender(config); + + assertFalse(appender.isEscapedMessages()); + assertFalse(appender.isCondensedNames()); + assertEquals(appender.getThreadPadding(), 10); + + int level = config.getLevel("com.mortbay"); + assertEquals(Level.WARN.toInt(), level); + + boolean stacks = config.getHideStacks("com.mortbay.Foo"); + assertFalse(stacks); + } + + @Test + public void testGetLevelExact() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.LEVEL", "WARN"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + int level = config.getLevel("com.mortbay"); + assertEquals(Level.WARN.toInt(), level); + } + + @Test + public void testGetLevelDotEnd() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.LEVEL", "WARN"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // extra trailing dot "." + int level = config.getLevel("com.mortbay."); + assertEquals(Level.WARN.toInt(), level); + } + + @Test + public void testGetLevelWithLevel() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.LEVEL", "WARN"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // asking for name with ".LEVEL" + int level = config.getLevel("com.mortbay.Bar.LEVEL"); + assertEquals(Level.WARN.toInt(), level); + } + + @Test + public void testGetLevelChild() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.LEVEL", "WARN"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + int level = config.getLevel("com.mortbay.Foo"); + assertEquals(Level.WARN.toInt(), level); + } + + @Test + public void testGetLevelDefault() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.LEVEL", "WARN"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // asking for name that isn't configured, returns default value + int level = config.getLevel("org.eclipse.jetty"); + assertEquals(Level.INFO.toInt(), level); + } + + @Test + public void testGetHideStacksExact() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.STACKS", "true"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + boolean val = config.getHideStacks("com.mortbay"); + assertTrue(val); + } + + @Test + public void testGetHideStacksDotEnd() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.STACKS", "true"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // extra trailing dot "." + boolean val = config.getHideStacks("com.mortbay."); + assertTrue(val); + } + + @Test + public void testGetHideStacksWithStacks() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.STACKS", "true"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // asking for name with ".STACKS" + boolean val = config.getHideStacks("com.mortbay.Bar.STACKS"); + assertTrue(val); + } + + @Test + public void testGetHideStacksChild() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.STACKS", "true"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + boolean val = config.getHideStacks("com.mortbay.Foo"); + assertTrue(val); + } + + @Test + public void testGetHideStacksDefault() + { + Properties props = new Properties(); + props.setProperty("com.mortbay.STACKS", "true"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + // asking for name that isn't configured, returns default value + boolean val = config.getHideStacks("org.eclipse.jetty"); + assertFalse(val); + } + + @Test + public void testGetLoggingLevelBad() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "WARN"); + props.setProperty("org.eclipse.jetty.bad.LEVEL", "EXPECTED_BAD_LEVEL"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Level (because of bad level value) + assertEquals(Level.WARN.toInt(), config.getLevel("org.eclipse.jetty.bad")); + } + + @Test + public void testGetLoggingLevelLowercase() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "warn"); + props.setProperty("org.eclipse.jetty.util.LEVEL", "info"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Level + assertEquals(Level.WARN.toInt(), config.getLevel("org.eclipse.jetty")); + // Specific Level + assertEquals(Level.INFO.toInt(), config.getLevel("org.eclipse.jetty.util")); + } + + @Test + public void testGetLoggingLevelRoot() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "DEBUG"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Levels + assertEquals(Level.DEBUG.toInt(), config.getLevel(null)); + assertEquals(Level.DEBUG.toInt(), config.getLevel("")); + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty")); + String name = JettyLoggerConfigurationTest.class.getName(); + assertEquals(Level.DEBUG.toInt(), config.getLevel(name), "Default Logging Level - " + name + " name"); + } + + @Test + public void testGetLoggingLevelFQCN() + { + String name = JettyLoggerTest.class.getName(); + Properties props = new Properties(); + props.setProperty(name + ".LEVEL", "ALL"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Levels + assertEquals(Level.INFO.toInt(), config.getLevel(null)); + assertEquals(Level.INFO.toInt(), config.getLevel("")); + assertEquals(Level.INFO.toInt(), config.getLevel("org.eclipse.jetty")); + + // Specified Level + assertEquals(JettyLogger.ALL, config.getLevel(name)); + } + + @Test + public void testGetLoggingLevelUtilLevel() + { + Properties props = new Properties(); + props.setProperty("org.eclipse.jetty.util.LEVEL", "DEBUG"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Levels + assertEquals(Level.INFO.toInt(), config.getLevel(null)); + assertEquals(Level.INFO.toInt(), config.getLevel("")); + assertEquals(Level.INFO.toInt(), config.getLevel("org.eclipse.jetty")); + assertEquals(Level.INFO.toInt(), config.getLevel("org.eclipse.jetty.server.BogusObject")); + assertEquals(Level.INFO.toInt(), config.getLevel(JettyLoggerConfigurationTest.class.getName())); + + // Configured Level + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty.util.Bogus")); + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty.util")); + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty.util.resource.PathResource")); + } + + @Test + public void testGetLoggingLevelMixedLevels() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "DEBUG"); + props.setProperty("org.eclipse.jetty.util.LEVEL", "WARN"); + props.setProperty("org.eclipse.jetty.util.ConcurrentHashMap.LEVEL", "ALL"); + + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + + // Default Levels + assertEquals(Level.DEBUG.toInt(), config.getLevel(null)); + assertEquals(Level.DEBUG.toInt(), config.getLevel("")); + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty")); + assertEquals(Level.DEBUG.toInt(), config.getLevel("org.eclipse.jetty.server.BogusObject")); + assertEquals(Level.DEBUG.toInt(), config.getLevel(JettyLoggerConfigurationTest.class.getName())); + + // Configured Level + assertEquals(Level.WARN.toInt(), config.getLevel("org.eclipse.jetty.util.MagicUtil")); + assertEquals(Level.WARN.toInt(), config.getLevel("org.eclipse.jetty.util")); + assertEquals(Level.WARN.toInt(), config.getLevel("org.eclipse.jetty.util.resource.PathResource")); + + assertEquals(JettyLogger.ALL, config.getLevel("org.eclipse.jetty.util.ConcurrentHashMap")); + } +} diff --git a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerTest.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerTest.java new file mode 100644 index 00000000000..86b6fd6db8d --- /dev/null +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JettyLoggerTest.java @@ -0,0 +1,614 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Properties; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.event.Level; + +import static java.time.ZoneOffset.UTC; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +/** + * Tests for JettyLogger and StdErrAppender + */ +public class JettyLoggerTest +{ + @BeforeEach + public void before() + { + Thread.currentThread().setName("tname"); + } + + @SuppressWarnings("PlaceholderCountMatchesArgumentCount") + @Test + public void testStdErrLogFormatSlf4jStrict() + { + Properties props = new Properties(); + props.setProperty(StdErrAppender.ZONEID_KEY, UTC.getId()); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + Logger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + log.info("testing:{},{}", "test", "format1"); + log.info("testing:{}", "test", "format2"); + log.info("testing", "test", "format3"); + log.info("testing:{},{}", "test", null); + log.info("testing {} {}", null, null); + log.info("testing:{}", null, null); + log.info("testing", null, null); + String msg = null; + log.info(msg, "test2", "format4"); + + System.err.println(output); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing:test,format1"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing:test"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing:test,null"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing null null"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing:null"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: testing"); + output.assertContains("INFO :oejl.JettyLoggerTest:tname: "); + } + + @Test + public void testStdErrLogDebug() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger("xxx"); + + log.setLevel(Level.DEBUG); + log.debug("testing {} {}", "test", "debug"); + log.info("testing {} {}", "test", "info"); + log.warn("testing {} {}", "test", "warn"); + log.setLevel(Level.INFO); + log.debug("YOU SHOULD NOT SEE THIS!"); + + output.assertContains("DEBUG:xxx:tname: testing test debug"); + output.assertContains("INFO :xxx:tname: testing test info"); + output.assertContains("WARN :xxx:tname: testing test warn"); + output.assertNotContains("YOU SHOULD NOT SEE THIS!"); + } + + @Test + public void testStdErrLogName() + { + Properties props = new Properties(); + props.setProperty(StdErrAppender.NAME_CONDENSE_KEY, "false"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger("test"); + + assertThat("Log.name", log.getName(), is("test")); + Logger next = factory.getLogger(log.getName() + ".next"); + assertThat("Log.name(child)", next.getName(), is("test.next")); + next.info("testing {} {}", "next", "info"); + + output.assertContains(":test.next:tname: testing next info"); + } + + @Test + public void testStdErrThrowable() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + // Common Throwable (for test) + Throwable th = new Throwable("Message"); + + // Capture raw string form + StringWriter tout = new StringWriter(); + th.printStackTrace(new PrintWriter(tout)); + String ths = tout.toString(); + + // Start test + JettyLogger log = factory.getJettyLogger("test"); + log.warn("ex", th); + output.assertContains(ths); + + th = new Throwable("Message with \033 escape"); + + log.warn("ex", th); + output.assertNotContains("Message with \033 escape"); + log.info(th.toString()); + output.assertNotContains("Message with \033 escape"); + + log.warn("ex", th); + output.assertContains("Message with ? escape"); + log.info(th.toString()); + output.assertContains("Message with ? escape"); + } + + /** + * Test to make sure that using a Null parameter on parameterized messages does not result in a NPE + */ + @SuppressWarnings({"PlaceholderCountMatchesArgumentCount", "ConstantConditions"}) + @Test + public void testParameterizedMessageNullValues() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + log.setLevel(Level.DEBUG); + + String nullMsg = null; + try (StacklessLogging ignored = new StacklessLogging(log)) + { + log.info("Testing info(msg,null,null) - {} {}", "arg0", "arg1"); + log.info("Testing info(msg,null,null) - {} {}", null, null); + log.info("Testing info(msg,null,null) - {}", null, null); + log.info("Testing info(msg,null,null)", null, null); + log.info(nullMsg, "Testing", "info(null,arg0,arg1)"); + log.info(nullMsg, null, null); + + log.debug("Testing debug(msg,null,null) - {} {}", "arg0", "arg1"); + log.debug("Testing debug(msg,null,null) - {} {}", null, null); + log.debug("Testing debug(msg,null,null) - {}", null, null); + log.debug("Testing debug(msg,null,null)", null, null); + log.debug(nullMsg, "Testing", "debug(null,arg0,arg1)"); + log.debug(nullMsg, null, null); + + log.debug("Testing debug(msg,null)"); + log.debug(null, new Throwable("Testing debug(null,thrw)").fillInStackTrace()); + + log.warn("Testing warn(msg,null,null) - {} {}", "arg0", "arg1"); + log.warn("Testing warn(msg,null,null) - {} {}", null, null); + log.warn("Testing warn(msg,null,null) - {}", null, null); + log.warn("Testing warn(msg,null,null)", null, null); + log.warn(nullMsg, "Testing", "warn(msg,arg0,arg1)"); + log.warn(nullMsg, null, null); + + log.warn("Testing warn(msg,null)"); + log.warn(nullMsg, new Throwable("Testing warn(msg,thrw)").fillInStackTrace()); + } + } + + /** + * Tests JettyLogger.warn() methods with level filtering. + *

+ * Should see WARN level messages, if level is set to WARN or below + */ + @Test + public void testWarnFiltering() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + try (StacklessLogging ignored = new StacklessLogging(log)) + { + // Start with default level + log.warn("See Me"); + + // Set to debug level + log.setLevel(Level.DEBUG); + log.warn("Hear Me"); + + // Set to warn level + log.setLevel(Level.WARN); + log.warn("Cheer Me"); + + log.warn("", new Throwable("out of focus")); + log.warn("shot issue", new Throwable("scene lost")); + + // Validate Output + // System.err.print(output); + output.assertContains("See Me"); + output.assertContains("Hear Me"); + output.assertContains("Cheer Me"); + + // Validate Stack Traces + output.assertContains(".JettyLoggerTest:tname: "); + output.assertContains("java.lang.Throwable: out of focus"); + output.assertContains("java.lang.Throwable: scene lost"); + } + } + + /** + * Tests JettyLogger.info() methods with level filtering. + *

+ * Should only see INFO level messages when level is set to {@link Level#INFO} and below. + */ + @Test + public void testInfoFiltering() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + try (StacklessLogging ignored = new StacklessLogging(log)) + { + // Normal/Default behavior + log.info("I will not buy"); + + // Level Debug + log.setLevel(Level.DEBUG); + log.info("this record"); + + // Level All + log.setLevel(Level.TRACE); + log.info("it is scratched."); + + log.info("", new Throwable("out of focus")); + log.info("shot issue", new Throwable("scene lost")); + + // Level Warn + log.setLevel(Level.WARN); + log.info("sorry?"); + log.info("", new Throwable("on editing room floor")); + + // Validate Output + output.assertContains("I will not buy"); + output.assertContains("this record"); + output.assertContains("it is scratched."); + output.assertNotContains("sorry?"); + + // Validate Stack Traces + output.assertNotContains(""); + output.assertNotContains("on editing room floor"); + + output.assertContains(".JettyLoggerTest:tname: "); + output.assertContains("java.lang.Throwable: out of focus"); + output.assertContains("java.lang.Throwable: scene lost"); + } + } + + /** + * Tests {@link Level#ERROR} filtering. + */ + @Test + public void testErrorFiltering() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + try (StacklessLogging ignored = new StacklessLogging(log)) + { + log.setLevel(Level.ERROR); + + // Various logging events + log.debug("Squelch"); + log.debug("Squelch", new RuntimeException("Squelch")); + log.info("Squelch"); + log.info("Squelch", new IllegalStateException("Squelch")); + log.warn("Squelch"); + log.warn("Squelch", new Exception("Squelch")); + log.trace("IGNORED", new Throwable("Squelch")); + + // Validate Output + output.assertNotContains("Squelch"); + } + } + + /** + * Tests level OFF filtering. + */ + @Test + public void testOffFiltering() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + try (StacklessLogging ignored = new StacklessLogging(log)) + { + log.setLevel(JettyLogger.OFF); + + // Various logging events + log.debug("Squelch"); + log.debug("Squelch", new RuntimeException("Squelch")); + log.info("Squelch"); + log.info("Squelch", new IllegalStateException("Squelch")); + log.warn("Squelch"); + log.warn("Squelch", new Exception("Squelch")); + log.trace("IGNORED", new Throwable("Squelch")); + + // Validate Output + output.assertNotContains("Squelch"); + } + } + + /** + * Tests StdErrLog.debug() methods with level filtering. + *

+ * Should only see DEBUG level messages when level is set to {@link Level#DEBUG} and below. + */ + @Test + public void testDebugFiltering() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + try (StacklessLogging ignored = new StacklessLogging(log)) + { + // Normal/Default behavior + log.debug("Tobacconist"); + log.debug("", new Throwable("on editing room floor")); + + // Level Debug + log.setLevel(Level.DEBUG); + log.debug("my hovercraft is"); + + log.debug("", new Throwable("out of focus")); + log.debug("shot issue", new Throwable("scene lost")); + + // Level All + log.setLevel(Level.TRACE); + log.debug("full of eels."); + + // Level Warn + log.setLevel(Level.WARN); + log.debug("what?"); + + // Validate Output + // System.err.print(output); + output.assertNotContains("Tobacconist"); + output.assertContains("my hovercraft is"); + output.assertContains("full of eels."); + output.assertNotContains("what?"); + + // Validate Stack Traces + output.assertNotContains(""); + output.assertNotContains("on editing room floor"); + + output.assertContains(".JettyLoggerTest:tname: "); + output.assertContains("java.lang.Throwable: out of focus"); + output.assertContains("java.lang.Throwable: scene lost"); + } + } + + @Test + public void testIsDebugEnabled() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + try (StacklessLogging ignored = new StacklessLogging(log)) + { + log.setLevel(Level.TRACE); + assertThat("log.level(trace).isDebugEnabled", log.isDebugEnabled(), is(true)); + + log.setLevel(Level.DEBUG); + assertThat("log.level(debug).isDebugEnabled", log.isDebugEnabled(), is(true)); + + log.setLevel(Level.INFO); + assertThat("log.level(info).isDebugEnabled", log.isDebugEnabled(), is(false)); + + log.setLevel(Level.WARN); + assertThat("log.level(warn).isDebugEnabled", log.isDebugEnabled(), is(false)); + + log.setLevel(Level.ERROR); + assertThat("log.level(error).isDebugEnabled", log.isDebugEnabled(), is(false)); + + log.setLevel(JettyLogger.OFF); + assertThat("log.level(null).isDebugEnabled", log.isDebugEnabled(), is(false)); + } + } + + @Test + public void testSetGetLevel() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger(JettyLoggerTest.class.getName()); + + try (StacklessLogging ignored = new StacklessLogging(log)) + { + log.setLevel(Level.TRACE); + assertThat("log.level(trace).getLevel()", log.getLevel(), is(Level.TRACE.toInt())); + + log.setLevel(Level.DEBUG); + assertThat("log.level(debug).getLevel()", log.getLevel(), is(Level.DEBUG.toInt())); + + log.setLevel(Level.INFO); + assertThat("log.level(info).getLevel()", log.getLevel(), is(Level.INFO.toInt())); + + log.setLevel(Level.WARN); + assertThat("log.level(warn).getLevel()", log.getLevel(), is(Level.WARN.toInt())); + + log.setLevel(Level.ERROR); + assertThat("log.level(error).getLevel()", log.getLevel(), is(Level.ERROR.toInt())); + + log.setLevel(888); + assertThat("log.level(888).getLevel()", log.getLevel(), is(888)); + } + } + + @Test + public void testToString() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger("xxx"); + + log.setLevel(Level.TRACE); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=TRACE")); + + log.setLevel(Level.DEBUG); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=DEBUG")); + + log.setLevel(Level.INFO); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=INFO")); + + log.setLevel(Level.WARN); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=WARN")); + + log.setLevel(Level.ERROR); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=ERROR")); + + log.setLevel(JettyLogger.OFF); + assertThat("Logger.toString", log.toString(), is("JettyLogger:xxx:LEVEL=OFF")); + } + + @Test + public void testConfiguredAndSetDebugEnabled() + { + Properties props = new Properties(); + props.setProperty("org.eclipse.jetty.util.LEVEL", "WARN"); + props.setProperty("org.eclipse.jetty.io.LEVEL", "WARN"); + + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger root = factory.getJettyLogger(""); + assertLevel(root, Level.INFO); // default + + JettyLogger log = factory.getJettyLogger("org.eclipse.jetty.util.Foo"); + assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(false)); + assertLevel(log, Level.WARN); // as configured + + // Boot stomp it all to debug + root.setLevel(Level.DEBUG); + assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(true)); + assertLevel(log, Level.DEBUG); // as stomped + + // Restore configured + factory.walkChildLoggers(root.getName(), (logger) -> + { + int configuredLevel = config.getLevel(logger.getName()); + logger.setLevel(configuredLevel); + }); + assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(false)); + assertLevel(log, Level.WARN); // as configured + } + + @Test + public void testSuppressed() + { + JettyLoggerConfiguration config = new JettyLoggerConfiguration(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + CapturedStream output = new CapturedStream(); + appender.setStream(output); + + JettyLogger log = factory.getJettyLogger("xxx"); + + Exception inner = new Exception("inner"); + inner.addSuppressed(new IllegalStateException() + { + { + addSuppressed(new Exception("branch0")); + } + }); + IOException outer = new IOException("outer", inner); + + outer.addSuppressed(new IllegalStateException() + { + { + addSuppressed(new Exception("branch1")); + } + }); + outer.addSuppressed(new IllegalArgumentException() + { + { + addSuppressed(new Exception("branch2")); + } + }); + + log.warn("problem", outer); + + output.assertContains("\t|\t|java.lang.Exception: branch2"); + output.assertContains("\t|\t|java.lang.Exception: branch1"); + output.assertContains("\t|\t|java.lang.Exception: branch0"); + } + + private void assertLevel(JettyLogger log, Level expectedLevel) + { + assertThat("Log[" + log.getName() + "].level", + JettyLogger.levelToString(log.getLevel()), is(expectedLevel.toString())); + } +} diff --git a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/Slf4jEffort.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/Slf4jEffort.java new file mode 100644 index 00000000000..132f00f3450 --- /dev/null +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/Slf4jEffort.java @@ -0,0 +1,240 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * Tool to help identify maven projects that need to be updated. + */ +public class Slf4jEffort +{ + public static void main(String[] args) throws Throwable + { + if (args.length < 1) + throw new IllegalStateException("No path specified: (expected) Slf4jEffort "); + + Path path = Paths.get(args[0]); + + if (!Files.exists(path)) + { + throw new FileNotFoundException(path.toString()); + } + + if (!Files.isDirectory(path)) + { + throw new IllegalStateException("Not a directory: " + path.toString()); + } + + Slf4jEffort effort = new Slf4jEffort(); + effort.scan(path); + } + + private Predicate notInTargetDirectory = (path) -> !path.toString().contains("/target/"); + + private void scan(Path root) throws IOException + { + AtomicInteger countJpms = new AtomicInteger(0); + AtomicInteger countPomSlf4jApis = new AtomicInteger(0); + AtomicInteger countPomSlf4jImpls = new AtomicInteger(0); + AtomicInteger countOldLogClassProps = new AtomicInteger(0); + + getProjectsStream(root).forEach((pom) -> + { + Path project = pom.getParent(); + try + { + Path testLoggingProps = project.resolve("src/test/resources/jetty-logging.properties"); + + boolean isMainSrcUsingLogging = getSources(project.resolve("src/main/java")).anyMatch(Slf4jEffort::isUsingLogging); + boolean isTestSrcUsingLogging = getSources(project.resolve("src/test/java")).anyMatch(Slf4jEffort::isUsingLogging); + + if (isMainSrcUsingLogging || isTestSrcUsingLogging) + { + // Must include slf4j in module-info and pom + Path moduleInfo = project.resolve("src/main/java/module-info.java"); + if (Files.exists(moduleInfo) && isMainSrcUsingLogging && !isLoggingJpmsPresent(moduleInfo)) + { + System.err.printf("[Missing: JPMS] %s%n", moduleInfo); + countJpms.incrementAndGet(); + } + + if (!isSlf4jDepPresent(pom)) + { + // System.err.printf("[Missing: Dep: slf4j-api] %s%n", pom); + countPomSlf4jApis.incrementAndGet(); + } + + if (isTestSrcUsingLogging && !isSlf4jImplDepPresent(pom)) + { + // System.err.printf("[Missing: Dep: jetty-slf4j-impl] %s%n", pom); + countPomSlf4jImpls.incrementAndGet(); + } + + if (Files.exists(testLoggingProps) && isOldLogClassPropPresent(testLoggingProps)) + { + System.err.printf("[Deprecated: log.class=LogImpl] %s%n", testLoggingProps); + countOldLogClassProps.incrementAndGet(); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + }); + + System.out.printf("JPMS (module-info.java) to fix: %d%n", countJpms.get()); + System.out.printf("POMS (pom.xml) - slf4j-api to fix: %d%n", countPomSlf4jApis.get()); + System.out.printf("POMS (pom.xml) - jetty-slf4j-impl to fix: %d%n", countPomSlf4jImpls.get()); + System.out.printf("PROPS (jetty-logging.properties) - to fix: %d%n", countOldLogClassProps.get()); + } + + private boolean isDepPresent(Path pom, String keyword) + { + try (BufferedReader reader = Files.newBufferedReader(pom)) + { + String line; + boolean inDependencies = false; + while ((line = reader.readLine()) != null) + { + if (line.contains("")) + { + inDependencies = true; + continue; + } + + if (line.contains("")) + { + inDependencies = false; + continue; + } + + if (inDependencies && line.contains(keyword)) + { + return true; + } + } + } + catch (IOException e) + { + System.err.printf(" [WARN] (%s) %s in %s%n", e.getClass().getName(), e.getMessage(), pom); + } + return false; + } + + private boolean isSlf4jDepPresent(Path pom) + { + return isDepPresent(pom, "slf4j-api"); + } + + private boolean isSlf4jImplDepPresent(Path pom) + { + return isDepPresent(pom, "jetty-slf4j-impl"); + } + + private boolean isOldLogClassPropPresent(Path propFile) + { + return getLineStream(propFile).anyMatch((line) -> line.startsWith("org.eclipse.jetty.util.log.class=")); + } + + private Stream getLineStream(Path file) + { + try + { + return Files.readAllLines(file, UTF_8).stream(); + } + catch (IOException e) + { + System.err.printf(" [WARN] (%s) %s in %s%n", e.getClass().getName(), e.getMessage(), file); + return Stream.empty(); + } + } + + private boolean isLoggingJpmsPresent(Path moduleInfo) + { + try (BufferedReader reader = Files.newBufferedReader(moduleInfo)) + { + String line; + while ((line = reader.readLine()) != null) + { + if (line.contains("requires org.slf4j;")) + { + return true; + } + } + } + catch (IOException e) + { + System.err.printf(" [WARN] (%s) %s in %s%n", e.getClass().getName(), e.getMessage(), moduleInfo); + } + return false; + } + + private static boolean isUsingLogging(Path src) + { + try (BufferedReader reader = Files.newBufferedReader(src)) + { + String line; + while ((line = reader.readLine()) != null) + { + if (line.startsWith("import org.eclipse.jetty.util.log.") || + line.startsWith("import org.slf4j.") || + line.startsWith("import org.eclipse.jetty.logging.")) + { + return true; + } + } + } + catch (IOException e) + { + System.err.printf(" [WARN] (%s) %s in %s%n", e.getClass().getName(), e.getMessage(), src); + } + return false; + } + + private Stream getSources(Path src) throws IOException + { + if (!Files.exists(src) || !Files.isDirectory(src)) + { + return Stream.empty(); + } + return Files.walk(src) + .filter(Files::isRegularFile) + .filter((path) -> path.getFileName().toString().endsWith(".java")); + } + + private Stream getProjectsStream(Path root) throws IOException + { + return Files.walk(root) + .filter(notInTargetDirectory) + .filter(Files::isRegularFile) + .filter((path) -> path.getFileName().toString().equals("pom.xml")); + } +} diff --git a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/StdErrAppenderTest.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/StdErrAppenderTest.java new file mode 100644 index 00000000000..38184450283 --- /dev/null +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/StdErrAppenderTest.java @@ -0,0 +1,49 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.logging; + +import java.util.Properties; + +import org.junit.jupiter.api.Test; +import org.slf4j.event.Level; + +public class StdErrAppenderTest +{ + @Test + public void testStdErrLogFormat() + { + Properties props = new Properties(); + props.setProperty(StdErrAppender.ZONEID_KEY, "UTC"); + JettyLoggerConfiguration config = new JettyLoggerConfiguration(props); + CapturedStream output = new CapturedStream(); + JettyLoggerFactory factory = new JettyLoggerFactory(config); + StdErrAppender appender = (StdErrAppender)factory.getRootLogger().getAppender(); + appender.setStream(output); + JettyLogger logger = factory.getJettyLogger("org.eclipse.jetty.logging.LogTest"); + + String threadName = "tname"; + // Feb 17th, 2020 at 19:11:35 UTC (with 563 millis) + long timestamp = 1581966695563L; + + appender.emit(logger, Level.INFO, timestamp, threadName, null, "testing:{},{}", "test", "format1"); + + System.err.println(output); + output.assertContains("2020-02-17 19:11:35.563:INFO :oejl.LogTest:tname: testing:test,format1"); + } +} diff --git a/jetty-spring/src/main/java/module-info.java b/jetty-spring/src/main/java/module-info.java index 754dedd15fd..1ab02eee967 100644 --- a/jetty-spring/src/main/java/module-info.java +++ b/jetty-spring/src/main/java/module-info.java @@ -24,6 +24,7 @@ module org.eclipse.jetty.spring exports org.eclipse.jetty.spring; requires transitive org.eclipse.jetty.xml; + requires org.slf4j; requires spring.beans; requires spring.core; diff --git a/jetty-start/pom.xml b/jetty-start/pom.xml index 062db44d4f3..c7b7b275b8b 100644 --- a/jetty-start/pom.xml +++ b/jetty-start/pom.xml @@ -72,6 +72,16 @@ org.eclipse.jetty jetty-util ${project.version} + + + org.slf4j + slf4j-api + + + org.eclipse.jetty + jetty-slf4j-impl + + org.eclipse.jetty.toolchain diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java index 8e2eb62b826..15eca129bfb 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java @@ -136,7 +136,7 @@ public class BaseBuilder } if (StartLog.isDebugEnabled()) - StartLog.debug("added=%s", newlyAdded); + StartLog.debug("Newly Added %s", newlyAdded); // Check the licenses if (startArgs.isLicenseCheckRequired()) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index a196a916a4f..f72f8387a77 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -310,7 +310,7 @@ public class Main modules.registerAll(); // 4) Active Module Resolution - for (String enabledModule : args.getEnabledModules()) + for (String enabledModule : modules.getSortedNames(args.getEnabledModules())) { for (String source : args.getSources(enabledModule)) { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index 492bbe4b14b..a4e3b97415d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -48,6 +48,7 @@ public class Modules implements Iterable private final List _modules = new ArrayList<>(); private final Map _names = new HashMap<>(); private final Map> _provided = new HashMap<>(); + private final Map _providedDefaults = new HashMap<>(); private final BaseHome _baseHome; private final StartArgs _args; private final Properties _deprecated = new Properties(); @@ -221,7 +222,22 @@ public class Modules implements Iterable _names.put(module.getName(), module); module.getProvides().forEach(n -> { - _provided.computeIfAbsent(n, k -> new HashSet()).add(module); + // Syntax can be : + // "" - for a simple provider reference + // "|default" - for a provider that is also the default implementation + String name = n; + boolean isDefaultProvider = false; + int idx = n.indexOf('|'); + if (idx > 0) + { + name = n.substring(0, idx); + isDefaultProvider = n.substring(idx + 1).equalsIgnoreCase("default"); + } + _provided.computeIfAbsent(name, k -> new HashSet<>()).add(module); + if (isDefaultProvider) + { + _providedDefaults.computeIfAbsent(name, k -> module.getName()); + } }); return module; @@ -285,6 +301,50 @@ public class Modules implements Iterable return enabled; } + public List getSortedAll() + { + List all = new ArrayList(_modules); + + TopologicalSort sort = new TopologicalSort<>(); + for (Module module : all) + { + Consumer add = name -> + { + Module dependency = _names.get(name); + if (dependency != null) + sort.addDependency(module, dependency); + + Set provided = _provided.get(name); + if (provided != null) + for (Module p : provided) + { + sort.addDependency(module, p); + } + }; + module.getDepends().forEach(add); + module.getOptional().forEach(add); + } + + sort.sort(all); + return all; + } + + public List getSortedNames(List enabledModules) + { + List all = getSortedAll(); + List order = new ArrayList<>(); + for (Module module : all) + { + String name = module.getName(); + if (enabledModules.contains(name)) + { + order.add(name); + } + } + + return order; + } + /** * Enable a module * @@ -305,11 +365,11 @@ public class Modules implements Iterable private void enable(Set newlyEnabled, Module module, String enabledFrom, boolean transitive) { - StartLog.debug("enable %s from %s transitive=%b", module, enabledFrom, transitive); + StartLog.debug("Enable [%s] from [%s] transitive=%b", module, enabledFrom, transitive); if (newlyEnabled.contains(module.getName())) { - StartLog.debug("Cycle at %s", module); + StartLog.debug("Already enabled [%s] from %s", module.getName(), module.getEnableSources()); return; } @@ -330,14 +390,13 @@ public class Modules implements Iterable throw new UsageException("Module %s provides %s, which is already provided by %s enabled in %s", module.getName(), name, p.getName(), p.getEnableSources()); } } - ; } } // Enable the module if (module.enable(enabledFrom, transitive)) { - StartLog.debug("enabled %s", module.getName()); + StartLog.debug("Enabled [%s]", module.getName()); newlyEnabled.add(module.getName()); // Expand module properties @@ -358,7 +417,7 @@ public class Modules implements Iterable } // Process module dependencies (always processed as may be dynamic) - StartLog.debug("Enabled module %s depends on %s", module.getName(), module.getDepends()); + StartLog.debug("Enabled module [%s] depends on %s", module.getName(), module.getDepends()); for (String dependsOnRaw : module.getDepends()) { boolean isRequired = Module.isRequiredDependency(dependsOnRaw); @@ -368,7 +427,7 @@ public class Modules implements Iterable // Look for modules that provide that dependency Set providers = getAvailableProviders(dependentModule); - StartLog.debug("Module %s depends on %s provided by %s", module, dependentModule, providers); + StartLog.debug("Module [%s] depends on [%s] provided by %s", module, dependentModule, providers); // If there are no known providers of the module if (providers.isEmpty()) @@ -403,24 +462,46 @@ public class Modules implements Iterable providers.stream().filter(m -> m.isEnabled() && !m.equals(module)).forEach(m -> enable(newlyEnabled, m, "transitive provider of " + dependentModule + " for " + module.getName(), true)); else { - // Is there an obvious default? - Optional dftProvider = (providers.size() == 1) - ? providers.stream().findFirst() - : providers.stream().filter(m -> m.getName().equals(dependentModule)).findFirst(); + Optional dftProvider = findDefaultProvider(providers, dependentModule); if (dftProvider.isPresent()) + { + StartLog.debug("Using [%s] provider as default for [%s]", dftProvider.get(), dependentModule); enable(newlyEnabled, dftProvider.get(), "transitive provider of " + dependentModule + " for " + module.getName(), true); - else if (StartLog.isDebugEnabled()) - StartLog.debug("Module %s requires a %s implementation from one of %s", module, dependentModule, providers); + } } } } + private Optional findDefaultProvider(Set providers, String dependsOn) + { + // Is it obvious? + if (providers.size() == 1) + return providers.stream().findFirst(); + + // If more then one provider impl, is there one specified as "default"? + if (providers.size() > 1) + { + // Was it specified with [provides] "name|default" ? + String defaultProviderName = _providedDefaults.get(dependsOn); + if (defaultProviderName != null) + { + return providers.stream().filter(m -> m.getName().equals(defaultProviderName)).findFirst(); + } + + // Or does a module exist with the same name as the [provides] "name" + return providers.stream().filter(m -> m.getName().equals(dependsOn)).findFirst(); + } + + // No default provider + return Optional.empty(); + } + private Set getAvailableProviders(String name) { // Get all available providers Set providers = _provided.get(name); - StartLog.debug("Providers of %s are %s", name, providers); + StartLog.debug("Providers of [%s] are %s", name, providers); if (providers == null || providers.isEmpty()) return Collections.emptySet(); @@ -455,7 +536,7 @@ public class Modules implements Iterable } } - StartLog.debug("Available providers of %s are %s", name, providers); + StartLog.debug("Available providers of [%s] are %s", name, providers); return providers; } @@ -496,7 +577,7 @@ public class Modules implements Iterable if (unsatisfied.length() > 0) unsatisfied.append(','); unsatisfied.append(m.getName()); - StartLog.error("Module %s requires a module providing %s from one of %s%n", m.getName(), d, providers); + StartLog.error("Module [%s] requires a module providing [%s] from one of %s%n", m.getName(), d, providers); } }); }); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 92adf58535b..d1aeb53b54f 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -617,7 +617,7 @@ public class StartArgs } } jmodAdds.add("ALL-MODULE-PATH"); - StartLog.debug("Expanded JPMS directives:%nadd-modules: %s%npatch-modules: %s%nadd-opens: %s%nadd-exports: %s%nadd-reads: %s", + StartLog.debug("Expanded JPMS directives:%n add-modules: %s%n patch-modules: %s%n add-opens: %s%n add-exports: %s%n add-reads: %s", jmodAdds, jmodPatch, jmodOpens, jmodExports, jmodReads); } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java index df84d80a4d1..be876154e53 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java @@ -44,11 +44,16 @@ public class StartLog private static volatile PrintStream logStream = System.err; private static final StartLog INSTANCE = new StartLog(); + private static void outLog(String level, String format, Object... args) + { + out.printf(level + ": " + format + "%n", args); + } + public static void debug(String format, Object... args) { if (INSTANCE.debug) { - out.printf(format + "%n", args); + outLog("DEBUG ", format, args); } } @@ -64,7 +69,7 @@ public class StartLog { if (INSTANCE.trace) { - out.printf("TRACE " + format + "%n", args); + outLog("TRACE ", format, args); } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 3ee887e088e..b39b23808ff 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -247,4 +247,45 @@ public class MainTest ConfigurationAssert.assertConfiguration(baseHome, args, "assert-home-with-spaces.txt"); } + + @Test + public void testProvidersUsingDefault() throws Exception + { + Path homePath = MavenTestingUtils.getTestResourceDir("providers-home").toPath().toRealPath(); + + List cmdLineArgs = new ArrayList<>(); + cmdLineArgs.add("user.dir=" + homePath); + cmdLineArgs.add("jetty.home=" + homePath); + cmdLineArgs.add("--module=server"); + + Main main = new Main(); + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); + BaseHome baseHome = main.getBaseHome(); + + assertThat("jetty.home", baseHome.getHome(), is(homePath.toString())); + assertThat("jetty.base", baseHome.getBase(), is(homePath.toString())); + + ConfigurationAssert.assertConfiguration(baseHome, args, "assert-providers-default.txt"); + } + + @Test + public void testProvidersUsingSpecific() throws Exception + { + Path homePath = MavenTestingUtils.getTestResourceDir("providers-home").toPath().toRealPath(); + + List cmdLineArgs = new ArrayList<>(); + cmdLineArgs.add("user.dir=" + homePath); + cmdLineArgs.add("jetty.home=" + homePath); + cmdLineArgs.add("--module=server"); + cmdLineArgs.add("--module=logging-b"); + + Main main = new Main(); + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); + BaseHome baseHome = main.getBaseHome(); + + assertThat("jetty.home", baseHome.getHome(), is(homePath.toString())); + assertThat("jetty.base", baseHome.getBase(), is(homePath.toString())); + + ConfigurationAssert.assertConfiguration(baseHome, args, "assert-providers-specific.txt"); + } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java index b156ca1cf2a..d8656bbbb76 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java @@ -24,7 +24,6 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -38,6 +37,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; @@ -83,19 +83,7 @@ public class TestUseCases PrintStream originalStream = StartLog.setStream(new PrintStream(out)); try { - // If there is a "{caseName}.prepare.txt" then use those - // lines as if you are calling start.jar once to setup - // the base directory. - List prepareArgs = lines(caseName + ".prepare.txt"); - if (!prepareArgs.isEmpty()) - { - Main main = new Main(); - List cmdLine = new ArrayList<>(); - cmdLine.add("--testing-mode"); - cmdLine.addAll(prepareArgs); - - main.start(main.processCommandLine(cmdLine)); - } + prepare(caseName); Main main = new Main(); List cmdLine = new ArrayList<>(); @@ -110,18 +98,23 @@ public class TestUseCases BaseHome baseHome = main.getBaseHome(); StartLog.setStream(originalStream); - String output = out.toString(StandardCharsets.UTF_8.name()); + String output = out.toString(UTF_8); ConfigurationAssert.assertConfiguration(baseHome, args, output, assertFile); } catch (Exception e) { - List exceptions = lines(assertFile).stream().filter(s -> s.startsWith("EX|")).collect(toList()); - if (exceptions.isEmpty()) + List expectedExceptions = lines(assertFile).stream().filter(s -> s.startsWith("EX|")).collect(toList()); + if (expectedExceptions.isEmpty()) throw e; - for (String ex : exceptions) + + for (String ex : expectedExceptions) { ex = ex.substring(3); - assertThat(e.toString(), Matchers.containsString(ex)); + if (!e.toString().contains(ex)) + { + System.err.println(out.toString(UTF_8)); + assertThat(e.toString(), Matchers.containsString(ex)); + } } } finally @@ -130,6 +123,23 @@ public class TestUseCases } } + private void prepare(String caseName) throws Exception + { + // If there is a "{caseName}.prepare.txt" then use those + // lines as if you are calling start.jar once to setup + // the base directory. + List prepareArgs = lines(caseName + ".prepare.txt"); + if (!prepareArgs.isEmpty()) + { + Main main = new Main(); + List cmdLine = new ArrayList<>(); + cmdLine.add("--testing-mode"); + cmdLine.addAll(prepareArgs); + + main.start(main.processCommandLine(cmdLine)); + } + } + private List lines(String filename) throws IOException { return lines(MavenTestingUtils.getTestResourcesPath().resolve("usecases" + File.separator + filename).toFile()); @@ -147,6 +157,8 @@ public class TestUseCases while ((line = buf.readLine()) != null) { line = line.trim(); + if (line.startsWith("#")) + continue; // skip this line if (line.length() > 0) { ret.add(line); diff --git a/jetty-start/src/test/resources/assert-providers-default.txt b/jetty-start/src/test/resources/assert-providers-default.txt new file mode 100644 index 00000000000..576efd12954 --- /dev/null +++ b/jetty-start/src/test/resources/assert-providers-default.txt @@ -0,0 +1,11 @@ +## The XMLs we expect (order is important) +XML|${jetty.base}/etc/logging-a.xml + +# The LIBs we expect (order is irrelevant) + +# The Properties we expect (order is irrelevant) +PROP|logging.prop=a +PROP|logging.a=true + +# Files / Directories to create + diff --git a/jetty-start/src/test/resources/assert-providers-specific.txt b/jetty-start/src/test/resources/assert-providers-specific.txt new file mode 100644 index 00000000000..b9132c3e0be --- /dev/null +++ b/jetty-start/src/test/resources/assert-providers-specific.txt @@ -0,0 +1,11 @@ +## The XMLs we expect (order is important) +XML|${jetty.base}/etc/logging-b.xml + +# The LIBs we expect (order is irrelevant) + +# The Properties we expect (order is irrelevant) +PROP|logging.prop=b +PROP|logging.b=true + +# Files / Directories to create + diff --git a/jetty-start/src/test/resources/providers-home/etc/logging-a.xml b/jetty-start/src/test/resources/providers-home/etc/logging-a.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/providers-home/etc/logging-b.xml b/jetty-start/src/test/resources/providers-home/etc/logging-b.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/providers-home/etc/logging-c.xml b/jetty-start/src/test/resources/providers-home/etc/logging-c.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/providers-home/modules/logging-a.mod b/jetty-start/src/test/resources/providers-home/modules/logging-a.mod new file mode 100644 index 00000000000..28f8973a239 --- /dev/null +++ b/jetty-start/src/test/resources/providers-home/modules/logging-a.mod @@ -0,0 +1,12 @@ +[tag] +logging + +[provides] +logging|default + +[xml] +etc/logging-a.xml + +[ini] +logging.prop=a +logging.a=true \ No newline at end of file diff --git a/jetty-start/src/test/resources/providers-home/modules/logging-b.mod b/jetty-start/src/test/resources/providers-home/modules/logging-b.mod new file mode 100644 index 00000000000..704088c8e92 --- /dev/null +++ b/jetty-start/src/test/resources/providers-home/modules/logging-b.mod @@ -0,0 +1,12 @@ +[tag] +logging + +[provides] +logging + +[xml] +etc/logging-b.xml + +[ini] +logging.prop=b +logging.b=true diff --git a/jetty-start/src/test/resources/providers-home/modules/logging-c.mod b/jetty-start/src/test/resources/providers-home/modules/logging-c.mod new file mode 100644 index 00000000000..b054e3ad88d --- /dev/null +++ b/jetty-start/src/test/resources/providers-home/modules/logging-c.mod @@ -0,0 +1,12 @@ +[tag] +logging + +[provides] +logging + +[xml] +etc/logging-c.xml + +[ini] +logging.prop=c +logging.c=true \ No newline at end of file diff --git a/jetty-start/src/test/resources/providers-home/modules/server.mod b/jetty-start/src/test/resources/providers-home/modules/server.mod new file mode 100644 index 00000000000..c0f21bd5bd9 --- /dev/null +++ b/jetty-start/src/test/resources/providers-home/modules/server.mod @@ -0,0 +1,8 @@ +[tag] +server + +[provides] +server + +[depends] +logging diff --git a/jetty-start/src/test/resources/usecases/loop.prepare.txt b/jetty-start/src/test/resources/usecases/loop.prepare.txt index 535d63e02ec..944681ab93a 100644 --- a/jetty-start/src/test/resources/usecases/loop.prepare.txt +++ b/jetty-start/src/test/resources/usecases/loop.prepare.txt @@ -1,2 +1,3 @@ --create-startd +# tom -> dick -> harry -> tom == CyclicException --add-to-start=tom diff --git a/jetty-unixsocket/jetty-unixsocket-client/src/main/java/module-info.java b/jetty-unixsocket/jetty-unixsocket-client/src/main/java/module-info.java index 6b2f8bc1d2c..0c7f8bf8bed 100644 --- a/jetty-unixsocket/jetty-unixsocket-client/src/main/java/module-info.java +++ b/jetty-unixsocket/jetty-unixsocket-client/src/main/java/module-info.java @@ -24,4 +24,5 @@ module org.eclipse.jetty.unixsocket.client requires jnr.unixsocket; requires transitive org.eclipse.jetty.client; requires org.eclipse.jetty.unixsocket.common; + requires org.slf4j; } diff --git a/jetty-unixsocket/jetty-unixsocket-client/src/test/resources/jetty-logging.properties b/jetty-unixsocket/jetty-unixsocket-client/src/test/resources/jetty-logging.properties index f6dad82a697..e67317312a5 100644 --- a/jetty-unixsocket/jetty-unixsocket-client/src/test/resources/jetty-logging.properties +++ b/jetty-unixsocket/jetty-unixsocket-client/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.unixsocket.LEVEL=DEBUG diff --git a/jetty-unixsocket/jetty-unixsocket-common/src/main/java/module-info.java b/jetty-unixsocket/jetty-unixsocket-common/src/main/java/module-info.java index 7e9c3fdcd5e..97f725825de 100644 --- a/jetty-unixsocket/jetty-unixsocket-common/src/main/java/module-info.java +++ b/jetty-unixsocket/jetty-unixsocket-common/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.unixsocket.common requires jnr.unixsocket; requires transitive org.eclipse.jetty.io; + requires org.slf4j; } diff --git a/jetty-unixsocket/jetty-unixsocket-server/src/main/java/module-info.java b/jetty-unixsocket/jetty-unixsocket-server/src/main/java/module-info.java index 98e3fd0a284..e7a7cf13625 100644 --- a/jetty-unixsocket/jetty-unixsocket-server/src/main/java/module-info.java +++ b/jetty-unixsocket/jetty-unixsocket-server/src/main/java/module-info.java @@ -24,4 +24,5 @@ module org.eclipse.jetty.unixsocket.server requires jnr.unixsocket; requires transitive org.eclipse.jetty.server; requires transitive org.eclipse.jetty.unixsocket.common; + requires org.slf4j; } diff --git a/jetty-unixsocket/jetty-unixsocket-server/src/test/resources/jetty-logging.properties b/jetty-unixsocket/jetty-unixsocket-server/src/test/resources/jetty-logging.properties index f6dad82a697..e67317312a5 100644 --- a/jetty-unixsocket/jetty-unixsocket-server/src/test/resources/jetty-logging.properties +++ b/jetty-unixsocket/jetty-unixsocket-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.unixsocket.LEVEL=DEBUG diff --git a/jetty-util-ajax/src/main/java/module-info.java b/jetty-util-ajax/src/main/java/module-info.java index 15e67f77178..e191453ed42 100644 --- a/jetty-util-ajax/src/main/java/module-info.java +++ b/jetty-util-ajax/src/main/java/module-info.java @@ -21,4 +21,5 @@ module org.eclipse.jetty.util.ajax exports org.eclipse.jetty.util.ajax; requires org.eclipse.jetty.util; + requires org.slf4j; } diff --git a/jetty-util/pom.xml b/jetty-util/pom.xml index a0188a09aab..90915e321cf 100644 --- a/jetty-util/pom.xml +++ b/jetty-util/pom.xml @@ -82,19 +82,10 @@ org.slf4j slf4j-api - provided - true - - org.slf4j - slf4j-jdk14 - ${slf4j.version} - test + org.eclipse.jetty + jetty-slf4j-impl diff --git a/jetty-util/src/main/config/etc/console-capture.xml b/jetty-util/src/main/config/etc/console-capture.xml index c8491fd31d8..439b0375241 100644 --- a/jetty-util/src/main/config/etc/console-capture.xml +++ b/jetty-util/src/main/config/etc/console-capture.xml @@ -1,26 +1,46 @@ - - - - - /yyyy_mm_dd.jetty.log - - - - - - - - - - - + + + + + /yyyy_mm_dd.jetty.log + + + + + + + + + + + + + + + + + + - - Console stderr/stdout captured to - - - + + org.eclipse.jetty + + Console stderr/stdout captured to + + + + + + + + + + + + + + diff --git a/jetty-util/src/main/config/modules/console-capture.mod b/jetty-util/src/main/config/modules/console-capture.mod index d9eaac43bef..f82d5316b58 100644 --- a/jetty-util/src/main/config/modules/console-capture.mod +++ b/jetty-util/src/main/config/modules/console-capture.mod @@ -7,6 +7,9 @@ including output from Jetty's default StdErrLog logging. [tags] logging +[depends] +logging + [xml] etc/console-capture.xml diff --git a/jetty-util/src/main/config/modules/jcl-slf4j.mod b/jetty-util/src/main/config/modules/jcl-slf4j.mod deleted file mode 100644 index cbe80839ca1..00000000000 --- a/jetty-util/src/main/config/modules/jcl-slf4j.mod +++ /dev/null @@ -1,25 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a Java Commons Logging (JCL) binding to SLF4J logging. - -[tags] -logging -jcl -slf4j -internal - -[depends] -slf4j-api -slf4j-impl - -[provides] -jcl-api -jcl-impl -slf4j+jcl - -[files] -maven://org.slf4j/jcl-over-slf4j/${slf4j.version}|lib/slf4j/jcl-over-slf4j-${slf4j.version}.jar - -[lib] -lib/slf4j/jcl-over-slf4j-${slf4j.version}.jar diff --git a/jetty-util/src/main/config/modules/jul-impl.mod b/jetty-util/src/main/config/modules/jul-impl.mod deleted file mode 100644 index 7ac22f79fb2..00000000000 --- a/jetty-util/src/main/config/modules/jul-impl.mod +++ /dev/null @@ -1,20 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configures the Java Util Logging mechanism - -[tags] -logging -jul -internal - -[provides] -jul-api -jul-impl - -[files] -basehome:modules/jul-impl - -[exec] --Djava.util.logging.config.file?=${jetty.base}/etc/java-util-logging.properties - diff --git a/jetty-util/src/main/config/modules/jul-impl/etc/java-util-logging.properties b/jetty-util/src/main/config/modules/jul-impl/etc/java-util-logging.properties deleted file mode 100644 index 867df054acb..00000000000 --- a/jetty-util/src/main/config/modules/jul-impl/etc/java-util-logging.properties +++ /dev/null @@ -1,12 +0,0 @@ -.level = INFO - -handlers = java.util.logging.ConsoleHandler -java.util.logging.ConsoleHandler.level = INFO -java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter - -#handlers = java.util.logging.FileHandler -#java.util.logging.FileHandler.pattern = ${jetty.logging.dir}/jetty%u.log -#java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter - -java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n - diff --git a/jetty-util/src/main/config/modules/jul-slf4j.mod b/jetty-util/src/main/config/modules/jul-slf4j.mod deleted file mode 100644 index 3cd9757d4f7..00000000000 --- a/jetty-util/src/main/config/modules/jul-slf4j.mod +++ /dev/null @@ -1,28 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a Java Util Logging binding to SLF4J logging. - -[tags] -logging -slf4j -internal - -[depends] -slf4j-api -slf4j-impl - -[provides] -jul-api -jul-impl -slf4j+jul - -[files] -maven://org.slf4j/jul-to-slf4j/${slf4j.version}|lib/slf4j/jul-to-slf4j-${slf4j.version}.jar -basehome:modules/jul-slf4j - -[lib] -lib/slf4j/jul-to-slf4j-${slf4j.version}.jar - -[exec] --Djava.util.logging.config.file?=${jetty.base}/etc/java-util-logging.properties diff --git a/jetty-util/src/main/config/modules/jul-slf4j/etc/java-util-logging.properties b/jetty-util/src/main/config/modules/jul-slf4j/etc/java-util-logging.properties deleted file mode 100644 index 9c03ec8420d..00000000000 --- a/jetty-util/src/main/config/modules/jul-slf4j/etc/java-util-logging.properties +++ /dev/null @@ -1,2 +0,0 @@ -handlers = org.slf4j.bridge.SLF4JBridgeHandler -.level = INFO diff --git a/jetty-util/src/main/config/modules/log4j-impl.mod b/jetty-util/src/main/config/modules/log4j-impl.mod deleted file mode 100644 index 5be5f77f385..00000000000 --- a/jetty-util/src/main/config/modules/log4j-impl.mod +++ /dev/null @@ -1,32 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a Log4j v1.2 API and implementation. -To receive jetty logs enable the jetty-slf4j and slf4j-log4j modules. - -[tags] -logging -log4j -internal - -[depends] -resources - -[provides] -log4j-api -log4j-impl - -[files] -maven://log4j/log4j/${log4j.version}|lib/log4j/log4j-${log4j.version}.jar -basehome:modules/log4j-impl - -[lib] -lib/log4j/log4j-${log4j.version}.jar - -[license] -Log4j is released under the Apache 2.0 license. -http://www.apache.org/licenses/LICENSE-2.0.html - -[ini] -log4j.version?=1.2.17 -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/log4j/ diff --git a/jetty-util/src/main/config/modules/log4j-impl/resources/log4j.xml b/jetty-util/src/main/config/modules/log4j-impl/resources/log4j.xml deleted file mode 100644 index 5e3d0a9ff95..00000000000 --- a/jetty-util/src/main/config/modules/log4j-impl/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/jetty-util/src/main/config/modules/log4j2-api.mod b/jetty-util/src/main/config/modules/log4j2-api.mod deleted file mode 100644 index f9766f6f531..00000000000 --- a/jetty-util/src/main/config/modules/log4j2-api.mod +++ /dev/null @@ -1,28 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides the Log4j v2 API - -[tags] -logging -log4j2 -log4j -internal - -[provides] -log4j2-api - -[files] -maven://org.apache.logging.log4j/log4j-api/${log4j2.version}|lib/log4j2/log4j-api-${log4j2.version}.jar - -[lib] -lib/log4j2/log4j-api-${log4j2.version}.jar - -[license] -Log4j is released under the Apache 2.0 license. -http://www.apache.org/licenses/LICENSE-2.0.html - -[ini] -log4j2.version?=2.11.2 -disruptor.version=3.4.2 -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/log4j2/ diff --git a/jetty-util/src/main/config/modules/log4j2-impl.mod b/jetty-util/src/main/config/modules/log4j2-impl.mod deleted file mode 100644 index d8997d971db..00000000000 --- a/jetty-util/src/main/config/modules/log4j2-impl.mod +++ /dev/null @@ -1,27 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a Log4j v2 implementation. -To receive jetty logs enable the jetty-slf4j, slf4j-log4j and log4j-log4j2 modules. - -[tags] -logging -log4j2 -log4j -internal - -[depends] -log4j2-api -resources - -[provides] -log4j2-impl - -[files] -maven://org.apache.logging.log4j/log4j-core/${log4j2.version}|lib/log4j2/log4j-core-${log4j2.version}.jar -maven://com.lmax/disruptor/${disruptor.version}|lib/log4j2/disruptor-${disruptor.version}.jar -basehome:modules/log4j2-impl - -[lib] -lib/log4j2/*.jar - diff --git a/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml b/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml deleted file mode 100644 index 400c779cb5c..00000000000 --- a/jetty-util/src/main/config/modules/log4j2-impl/resources/log4j2.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - ${sys:jetty.logging.dir:-logs} - - - - - - %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n - - - - - - - %d [%t] %-5p %c %x - %m%n - - - - - - - - - - - - - - - - - - - diff --git a/jetty-util/src/main/config/modules/log4j2-slf4j.mod b/jetty-util/src/main/config/modules/log4j2-slf4j.mod deleted file mode 100644 index 6c351779b10..00000000000 --- a/jetty-util/src/main/config/modules/log4j2-slf4j.mod +++ /dev/null @@ -1,25 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a Log4j v2 binding to SLF4J logging. - -[tags] -logging -log4j2 -log4j -slf4j -internal - -[depends] -log4j2-api -slf4j-api - -[provides] -log4j2-impl - -[files] -maven://org.apache.logging.log4j/log4j-to-slf4j/${log4j2.version}|lib/log4j2/log4j-to-slf4j-${log4j2.version}.jar - -[lib] -lib/log4j2/log4j-slf4j-to-${log4j2.version}.jar - diff --git a/jetty-util/src/main/config/modules/logback-impl.mod b/jetty-util/src/main/config/modules/logback-impl.mod deleted file mode 100644 index 18c067b4d3f..00000000000 --- a/jetty-util/src/main/config/modules/logback-impl.mod +++ /dev/null @@ -1,40 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides the logback core implementation -and logback-access - -[tags] -logging -internal - -[depends] -resources - -[files] -maven://ch.qos.logback/logback-core/${logback.version}|lib/logback/logback-core-${logback.version}.jar -basehome:modules/logback-impl - -[lib] -lib/logback/logback-core-${logback.version}.jar - -[license] -Logback: the reliable, generic, fast and flexible logging framework. -Copyright (C) 1999-2012, QOS.ch. All rights reserved. - -This program and the accompanying materials are dual-licensed under -either: - - the terms of the Eclipse Public License v1.0 - as published by the Eclipse Foundation: - http://www.eclipse.org/legal/epl-v10.html - -or (per the licensee's choosing) under - - the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation: - http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html - -[ini] -logback.version?=1.2.3 -jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/logback/ diff --git a/jetty-util/src/main/config/modules/logback-impl/resources/logback.xml b/jetty-util/src/main/config/modules/logback-impl/resources/logback.xml deleted file mode 100644 index 552845e3249..00000000000 --- a/jetty-util/src/main/config/modules/logback-impl/resources/logback.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - %-4relative [%thread] %-5level %logger{35} - %msg %n - - - - - - - - - - diff --git a/jetty-util/src/main/config/modules/logging-jetty.mod b/jetty-util/src/main/config/modules/logging-jetty.mod deleted file mode 100644 index 65f926d3a89..00000000000 --- a/jetty-util/src/main/config/modules/logging-jetty.mod +++ /dev/null @@ -1,17 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging mechanism. -Provides a ${jetty.base}/resources/jetty-logging.properties. - -[tags] -logging - -[depends] -resources - -[provides] -logging - -[files] -basehome:modules/logging-jetty diff --git a/jetty-util/src/main/config/modules/logging-jetty/resources/jetty-logging.properties b/jetty-util/src/main/config/modules/logging-jetty/resources/jetty-logging.properties deleted file mode 100644 index 07e04350fed..00000000000 --- a/jetty-util/src/main/config/modules/logging-jetty/resources/jetty-logging.properties +++ /dev/null @@ -1,12 +0,0 @@ -## Force jetty logging implementation -#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog - -## Set logging levels from: ALL, DEBUG, INFO, WARN, OFF -#org.eclipse.jetty.LEVEL=INFO -#com.example.LEVEL=INFO - -## Hide stacks traces in logs? -#com.example.STACKS=false - -## Show the source file of a log location? -#com.example.SOURCE=false diff --git a/jetty-util/src/main/config/modules/logging-jul.mod b/jetty-util/src/main/config/modules/logging-jul.mod deleted file mode 100644 index bc0d414ba73..00000000000 --- a/jetty-util/src/main/config/modules/logging-jul.mod +++ /dev/null @@ -1,18 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging to use Java Util Logging (jul) -SLF4J is used as the core logging mechanism. - -[tags] -logging - -[depends] -slf4j-jul -jul-impl - -[provides] -logging - -[exec] --Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty-util/src/main/config/modules/logging-log4j.mod b/jetty-util/src/main/config/modules/logging-log4j.mod deleted file mode 100644 index 75b2f29b36d..00000000000 --- a/jetty-util/src/main/config/modules/logging-log4j.mod +++ /dev/null @@ -1,18 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging to use Log4j Logging -SLF4J is used as the core logging mechanism. - -[tags] -logging - -[depends] -slf4j-log4j -log4j-impl - -[provides] -logging - -[exec] --Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty-util/src/main/config/modules/logging-log4j2.mod b/jetty-util/src/main/config/modules/logging-log4j2.mod deleted file mode 100644 index 34bea9b9be6..00000000000 --- a/jetty-util/src/main/config/modules/logging-log4j2.mod +++ /dev/null @@ -1,18 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging to use log4j version 2 -SLF4J is used as the core logging mechanism. - -[tags] -logging - -[depends] -slf4j-log4j2 -log4j2-impl - -[provides] -logging - -[exec] --Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty-util/src/main/config/modules/logging-logback.mod b/jetty-util/src/main/config/modules/logging-logback.mod deleted file mode 100644 index f6699c0257d..00000000000 --- a/jetty-util/src/main/config/modules/logging-logback.mod +++ /dev/null @@ -1,18 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging to use Logback Logging. -SLF4J is used as the core logging mechanism. - -[tags] -logging - -[depends] -slf4j-logback -logback-impl - -[provides] -logging - -[exec] --Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty-util/src/main/config/modules/logging-slf4j.mod b/jetty-util/src/main/config/modules/logging-slf4j.mod deleted file mode 100644 index aac12a87ef7..00000000000 --- a/jetty-util/src/main/config/modules/logging-slf4j.mod +++ /dev/null @@ -1,18 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Configure jetty logging to use slf4j. -Any slf4j-impl implementation is used - -[tags] -logging - -[depends] -slf4j-api -slf4j-impl - -[provides] -logging - -[exec] --Dorg.eclipse.jetty.util.log.class?=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty-util/src/main/config/modules/slf4j-jul.mod b/jetty-util/src/main/config/modules/slf4j-jul.mod deleted file mode 100644 index a0e072daab2..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-jul.mod +++ /dev/null @@ -1,22 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a SLF4J binding to Java Util Logging (JUL) logging. - -[tags] -logging -slf4j -internal - -[depends] -slf4j-api - -[provides] -slf4j-impl -slf4j+jul - -[files] -maven://org.slf4j/slf4j-jdk14/${slf4j.version}|lib/slf4j/slf4j-jdk14-${slf4j.version}.jar - -[lib] -lib/slf4j/slf4j-jdk14-${slf4j.version}.jar diff --git a/jetty-util/src/main/config/modules/slf4j-log4j.mod b/jetty-util/src/main/config/modules/slf4j-log4j.mod deleted file mode 100644 index d61ded58678..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-log4j.mod +++ /dev/null @@ -1,25 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a SLF4J binding to the Log4j v1.2 API logging. - -[tags] -logging -log4j -slf4j -internal - -[depends] -slf4j-api -log4j-api -log4j-impl - -[provides] -slf4j-impl - -[files] -maven://org.slf4j/slf4j-log4j12/${slf4j.version}|lib/slf4j/slf4j-log4j12-${slf4j.version}.jar - -[lib] -lib/slf4j/slf4j-log4j12-${slf4j.version}.jar - diff --git a/jetty-util/src/main/config/modules/slf4j-log4j2.mod b/jetty-util/src/main/config/modules/slf4j-log4j2.mod deleted file mode 100644 index fa6ff70810f..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-log4j2.mod +++ /dev/null @@ -1,25 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a SLF4J binding to Log4j v2 logging. - -[tags] -logging -log4j2 -log4j -slf4j -internal - -[depends] -slf4j-api -log4j2-api -log4j2-impl - -[provides] -slf4j-impl - -[files] -maven://org.apache.logging.log4j/log4j-slf4j18-impl/${log4j2.version}|lib/log4j2/log4j-slf4j18-impl-${log4j2.version}.jar - -[lib] -lib/log4j2/log4j-slf4j18-impl-${log4j2.version}.jar diff --git a/jetty-util/src/main/config/modules/slf4j-logback.mod b/jetty-util/src/main/config/modules/slf4j-logback.mod deleted file mode 100644 index f9ebe8bfe1d..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-logback.mod +++ /dev/null @@ -1,24 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides a SLF4J binding to Logback logging. - -[tags] -logging -slf4j -internal - -[depends] -slf4j-api -logback-impl -resources - -[provides] -slf4j-impl - -[files] -maven://ch.qos.logback/logback-classic/${logback.version}|lib/logback/logback-classic-${logback.version}.jar - -[lib] -lib/logback/logback-classic-${logback.version}.jar - diff --git a/jetty-util/src/main/config/modules/slf4j-simple-impl.mod b/jetty-util/src/main/config/modules/slf4j-simple-impl.mod deleted file mode 100644 index bc1b7fd92f8..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-simple-impl.mod +++ /dev/null @@ -1,24 +0,0 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Provides SLF4J simple logging implementation. -To receive jetty logs enable the jetty-slf4j module. - -[tags] -logging -slf4j -internal - -[depends] -slf4j-api -resources - -[provides] -slf4j-impl - -[files] -maven://org.slf4j/slf4j-simple/${slf4j.version}|lib/slf4j/slf4j-simple-${slf4j.version}.jar -basehome:modules/slf4j-simple-impl - -[lib] -lib/slf4j/slf4j-simple-${slf4j.version}.jar diff --git a/jetty-util/src/main/config/modules/slf4j-simple-impl/resources/simplelogger.properties b/jetty-util/src/main/config/modules/slf4j-simple-impl/resources/simplelogger.properties deleted file mode 100644 index 060cf1cb61e..00000000000 --- a/jetty-util/src/main/config/modules/slf4j-simple-impl/resources/simplelogger.properties +++ /dev/null @@ -1,6 +0,0 @@ -#org.slf4j.simpleLogger.logFile=logs/jetty.log -org.slf4j.simpleLogger.defaultLogLevel=info -org.slf4j.simpleLogger.showDateTime=true -org.slf4j.simpleLogger.showThreadName=true - -#org.slf4j.simpleLogger.log.org.eclipse.jetty=debug diff --git a/jetty-util/src/main/java/module-info.java b/jetty-util/src/main/java/module-info.java index b7853a2a030..1a175df1218 100644 --- a/jetty-util/src/main/java/module-info.java +++ b/jetty-util/src/main/java/module-info.java @@ -23,6 +23,7 @@ module org.eclipse.jetty.util exports org.eclipse.jetty.util; exports org.eclipse.jetty.util.annotation; exports org.eclipse.jetty.util.component; + exports org.eclipse.jetty.util.compression; exports org.eclipse.jetty.util.log; exports org.eclipse.jetty.util.preventers; exports org.eclipse.jetty.util.resource; @@ -31,10 +32,10 @@ module org.eclipse.jetty.util exports org.eclipse.jetty.util.statistic; exports org.eclipse.jetty.util.thread; exports org.eclipse.jetty.util.thread.strategy; - exports org.eclipse.jetty.util.compression; // Required by SSL code (for X509). requires transitive java.naming; + requires org.slf4j; // Only required if using AppContextLeakPreventer/AWTLeakPreventer. requires static java.desktop; @@ -44,8 +45,6 @@ module org.eclipse.jetty.util requires static java.sql; // Only required if using DOMLeakPreventer. requires static java.xml; - // Only required if using Slf4jLog. - requires static org.slf4j; uses CredentialProvider; } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java b/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java index d8cb83f11a5..7d7a8ee716b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java @@ -24,6 +24,8 @@ package org.eclipse.jetty.util; */ public class JavaVersion { + // IMPORTANT NOTE: This class cannot use Logging, as this class is used by jetty-start + /** * Context attribute that can be set to target a different version of the jvm than the current runtime. * Acceptable values should correspond to those returned by JavaVersion.getPlatform(). diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ManifestUtils.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ManifestUtils.java index d4f0c9efba9..8c3dbecf155 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ManifestUtils.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ManifestUtils.java @@ -27,6 +27,8 @@ import java.util.jar.Manifest; public class ManifestUtils { + // IMPORTANT NOTE: This class cannot use Logging, as this class is used by jetty-start + private ManifestUtils() { } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java index b75ada9bd54..96f8ae3a864 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java @@ -47,6 +47,8 @@ import java.util.TreeSet; */ public class TopologicalSort { + // IMPORTANT NOTE: This class cannot use Logging, as this class is used by jetty-start + private final Map> _dependencies = new HashMap<>(); /** diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java deleted file mode 100644 index cb69588f732..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java +++ /dev/null @@ -1,257 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.util.Properties; - -/** - * Abstract Logger. - * Manages the atomic registration of the logger by name. - */ -public abstract class AbstractLogger implements Logger -{ - public static final int LEVEL_DEFAULT = -1; - public static final int LEVEL_ALL = 0; - public static final int LEVEL_DEBUG = 1; - public static final int LEVEL_INFO = 2; - public static final int LEVEL_WARN = 3; - public static final int LEVEL_OFF = 10; - - @Override - public final Logger getLogger(String name) - { - if (isBlank(name)) - return this; - - final String basename = getName(); - final String fullname = (isBlank(basename) || Log.getRootLogger() == this) ? name : (basename + "." + name); - - Logger logger = Log.getLoggers().get(fullname); - if (logger == null) - { - Logger newlog = newLogger(fullname); - - logger = Log.getMutableLoggers().putIfAbsent(fullname, newlog); - if (logger == null) - logger = newlog; - } - - return logger; - } - - protected abstract Logger newLogger(String fullname); - - /** - * A more robust form of name blank test. Will return true for null names, and names that have only whitespace - * - * @param name the name to test - * @return true for null or blank name, false if any non-whitespace character is found. - */ - private static boolean isBlank(String name) - { - if (name == null) - { - return true; - } - int size = name.length(); - char c; - for (int i = 0; i < size; i++) - { - c = name.charAt(i); - if (!Character.isWhitespace(c)) - { - return false; - } - } - return true; - } - - /** - * Get the Logging Level for the provided log name. Using the FQCN first, then each package segment from longest to - * shortest. - * - * @param props the properties to check - * @param name the name to get log for - * @return the logging level - */ - public static int lookupLoggingLevel(Properties props, final String name) - { - if ((props == null) || (props.isEmpty()) || name == null) - return LEVEL_DEFAULT; - - // Calculate the level this named logger should operate under. - // Checking with FQCN first, then each package segment from longest to shortest. - String nameSegment = name; - - while ((nameSegment != null) && (nameSegment.length() > 0)) - { - String levelStr = props.getProperty(nameSegment + ".LEVEL"); - // System.err.printf("[StdErrLog.CONFIG] Checking for property [%s.LEVEL] = %s%n",nameSegment,levelStr); - int level = getLevelId(nameSegment + ".LEVEL", levelStr); - if (level != (-1)) - { - return level; - } - - // Trim and try again. - int idx = nameSegment.lastIndexOf('.'); - if (idx >= 0) - { - nameSegment = nameSegment.substring(0, idx); - } - else - { - nameSegment = null; - } - } - - // Default Logging Level - return LEVEL_DEFAULT; - } - - public static String getLoggingProperty(Properties props, String name, String property) - { - // Calculate the level this named logger should operate under. - // Checking with FQCN first, then each package segment from longest to shortest. - String nameSegment = name; - - while ((nameSegment != null) && (nameSegment.length() > 0)) - { - String s = props.getProperty(nameSegment + "." + property); - if (s != null) - return s; - - // Trim and try again. - int idx = nameSegment.lastIndexOf('.'); - nameSegment = (idx >= 0) ? nameSegment.substring(0, idx) : null; - } - - return null; - } - - protected static int getLevelId(String levelSegment, String levelName) - { - if (levelName == null) - { - return -1; - } - String levelStr = levelName.trim(); - if ("ALL".equalsIgnoreCase(levelStr)) - { - return LEVEL_ALL; - } - else if ("DEBUG".equalsIgnoreCase(levelStr)) - { - return LEVEL_DEBUG; - } - else if ("INFO".equalsIgnoreCase(levelStr)) - { - return LEVEL_INFO; - } - else if ("WARN".equalsIgnoreCase(levelStr)) - { - return LEVEL_WARN; - } - else if ("OFF".equalsIgnoreCase(levelStr)) - { - return LEVEL_OFF; - } - - System.err.println("Unknown StdErrLog level [" + levelSegment + "]=[" + levelStr + "], expecting only [ALL, DEBUG, INFO, WARN, OFF] as values."); - return -1; - } - - /** - * Condenses a classname by stripping down the package name to just the first character of each package name - * segment.Configured - * - *

-     * Examples:
-     * "org.eclipse.jetty.test.FooTest"           = "oejt.FooTest"
-     * "org.eclipse.jetty.server.logging.LogTest" = "orjsl.LogTest"
-     * 
- * - * @param classname the fully qualified class name - * @return the condensed name - */ - @SuppressWarnings("Duplicates") - protected static String condensePackageString(String classname) - { - if (classname == null || classname.isEmpty()) - { - return ""; - } - - int rawLen = classname.length(); - StringBuilder dense = new StringBuilder(rawLen); - boolean foundStart = false; - boolean hasPackage = false; - int startIdx = -1; - int endIdx = -1; - for (int i = 0; i < rawLen; i++) - { - char c = classname.charAt(i); - if (!foundStart) - { - foundStart = Character.isJavaIdentifierStart(c); - if (foundStart) - { - if (startIdx >= 0) - { - dense.append(classname.charAt(startIdx)); - hasPackage = true; - } - startIdx = i; - } - } - - if (foundStart) - { - if (!Character.isJavaIdentifierPart(c)) - { - foundStart = false; - } - else - { - endIdx = i; - } - } - } - // append remaining from startIdx - if ((startIdx >= 0) && (endIdx >= startIdx)) - { - if (hasPackage) - { - dense.append('.'); - } - dense.append(classname, startIdx, endIdx + 1); - } - - return dense.toString(); - } - - @Override - public void debug(String msg, long arg) - { - if (isDebugEnabled()) - { - debug(msg, new Object[]{arg}); - } - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java deleted file mode 100644 index 4f82c45c3f9..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java +++ /dev/null @@ -1,303 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.LogRecord; - -import org.eclipse.jetty.util.Loader; - -/** - *

- * Implementation of Jetty {@link Logger} based on {@link java.util.logging.Logger}. - *

- * - *

- * You can also set the logger level using - * standard java.util.logging configuration. - *

- * - * Configuration Properties: - *
- *
${name|hierarchy}.LEVEL=(ALL|DEBUG|INFO|WARN|OFF)
- *
- * Sets the level that the Logger should log at.
- * Names can be a package name, or a fully qualified class name.
- * Default: The default from the java.util.logging mechanism/configuration - *
- *
org.eclipse.jetty.util.log.javautil.PROPERTIES=<property-resource-name>
- *
If set, it is used as a classpath resource name to find a java.util.logging - * property file. - *
- * Default: null - *
- *
org.eclipse.jetty.util.log.javautil.SOURCE=(true|false)
- *
Set the LogRecord source class and method for JavaUtilLog.
- * Default: true - *
- *
org.eclipse.jetty.util.log.SOURCE=(true|false)
- *
Set the LogRecord source class and method for all Loggers.
- * Default: depends on Logger class - *
- *
- */ -public class JavaUtilLog extends AbstractLogger -{ - private static final boolean SOURCE = - Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.SOURCE", - Log.getProperty("org.eclipse.jetty.util.log.javautil.SOURCE", "true"))); - - private static boolean __initialized = false; - - private Level _configuredLevel; - private java.util.logging.Logger _logger; - - public JavaUtilLog() - { - this("org.eclipse.jetty.util.log.javautil"); - } - - public JavaUtilLog(String name) - { - synchronized (JavaUtilLog.class) - { - if (!__initialized) - { - __initialized = true; - - final String properties = Log.getProperty("org.eclipse.jetty.util.log.javautil.PROPERTIES", null); - if (properties != null) - { - AccessController.doPrivileged(new PrivilegedAction() - { - @Override - public Object run() - { - try - { - URL props = Loader.getResource(properties); - if (props != null) - LogManager.getLogManager().readConfiguration(props.openStream()); - } - catch (Throwable e) - { - System.err.println("[WARN] Error loading logging config: " + properties); - e.printStackTrace(System.err); - } - - return null; - } - }); - } - } - } - - _logger = java.util.logging.Logger.getLogger(name); - - switch (lookupLoggingLevel(Log.getProperties(), name)) - { - case LEVEL_ALL: - _logger.setLevel(Level.ALL); - break; - case LEVEL_DEBUG: - _logger.setLevel(Level.FINE); - break; - case LEVEL_INFO: - _logger.setLevel(Level.INFO); - break; - case LEVEL_WARN: - _logger.setLevel(Level.WARNING); - break; - case LEVEL_OFF: - _logger.setLevel(Level.OFF); - break; - case LEVEL_DEFAULT: - default: - break; - } - - _configuredLevel = _logger.getLevel(); - } - - @Override - public String getName() - { - return _logger.getName(); - } - - protected void log(Level level, String msg, Throwable thrown) - { - LogRecord record = new LogRecord(level, msg); - if (thrown != null) - record.setThrown(thrown); - record.setLoggerName(_logger.getName()); - if (SOURCE) - { - StackTraceElement[] stack = new Throwable().getStackTrace(); - for (int i = 0; i < stack.length; i++) - { - StackTraceElement e = stack[i]; - if (!e.getClassName().equals(JavaUtilLog.class.getName())) - { - record.setSourceClassName(e.getClassName()); - record.setSourceMethodName(e.getMethodName()); - break; - } - } - } - _logger.log(record); - } - - @Override - public void warn(String msg, Object... args) - { - if (_logger.isLoggable(Level.WARNING)) - log(Level.WARNING, format(msg, args), null); - } - - @Override - public void warn(Throwable thrown) - { - if (_logger.isLoggable(Level.WARNING)) - log(Level.WARNING, "", thrown); - } - - @Override - public void warn(String msg, Throwable thrown) - { - if (_logger.isLoggable(Level.WARNING)) - log(Level.WARNING, msg, thrown); - } - - @Override - public void info(String msg, Object... args) - { - if (_logger.isLoggable(Level.INFO)) - log(Level.INFO, format(msg, args), null); - } - - @Override - public void info(Throwable thrown) - { - if (_logger.isLoggable(Level.INFO)) - log(Level.INFO, "", thrown); - } - - @Override - public void info(String msg, Throwable thrown) - { - if (_logger.isLoggable(Level.INFO)) - log(Level.INFO, msg, thrown); - } - - @Override - public boolean isDebugEnabled() - { - return _logger.isLoggable(Level.FINE); - } - - @Override - public void setDebugEnabled(boolean enabled) - { - if (enabled) - { - _configuredLevel = _logger.getLevel(); - _logger.setLevel(Level.FINE); - } - else - { - _logger.setLevel(_configuredLevel); - } - } - - @Override - public void debug(String msg, Object... args) - { - if (_logger.isLoggable(Level.FINE)) - log(Level.FINE, format(msg, args), null); - } - - @Override - public void debug(String msg, long arg) - { - if (_logger.isLoggable(Level.FINE)) - log(Level.FINE, format(msg, arg), null); - } - - @Override - public void debug(Throwable thrown) - { - if (_logger.isLoggable(Level.FINE)) - log(Level.FINE, "", thrown); - } - - @Override - public void debug(String msg, Throwable thrown) - { - if (_logger.isLoggable(Level.FINE)) - log(Level.FINE, msg, thrown); - } - - /** - * Create a Child Logger of this Logger. - */ - @Override - protected Logger newLogger(String fullname) - { - return new JavaUtilLog(fullname); - } - - @Override - public void ignore(Throwable ignored) - { - if (_logger.isLoggable(Level.FINEST)) - log(Level.FINEST, Log.IGNORED, ignored); - } - - private String format(String msg, Object... args) - { - msg = String.valueOf(msg); // Avoids NPE - String braces = "{}"; - StringBuilder builder = new StringBuilder(); - int start = 0; - for (Object arg : args) - { - int bracesIndex = msg.indexOf(braces, start); - if (bracesIndex < 0) - { - builder.append(msg.substring(start)); - builder.append(" "); - builder.append(arg); - start = msg.length(); - } - else - { - builder.append(msg.substring(start, bracesIndex)); - builder.append(String.valueOf(arg)); - start = bracesIndex + braces.length(); - } - } - builder.append(msg.substring(start)); - return builder.toString(); - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyAwareLogger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyAwareLogger.java deleted file mode 100644 index f4021798185..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyAwareLogger.java +++ /dev/null @@ -1,446 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import org.slf4j.Marker; -import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MessageFormatter; - -/** - * JettyAwareLogger is used to fix a FQCN bug that arises from how Jetty - * Log uses an indirect slf4j implementation. - * - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670 - */ -class JettyAwareLogger implements org.slf4j.Logger -{ - private static final int DEBUG = org.slf4j.spi.LocationAwareLogger.DEBUG_INT; - private static final int ERROR = org.slf4j.spi.LocationAwareLogger.ERROR_INT; - private static final int INFO = org.slf4j.spi.LocationAwareLogger.INFO_INT; - private static final int TRACE = org.slf4j.spi.LocationAwareLogger.TRACE_INT; - private static final int WARN = org.slf4j.spi.LocationAwareLogger.WARN_INT; - - private static final String FQCN = Slf4jLog.class.getName(); - private final org.slf4j.spi.LocationAwareLogger _logger; - - public JettyAwareLogger(org.slf4j.spi.LocationAwareLogger logger) - { - _logger = logger; - } - - @Override - public void debug(String msg) - { - log(null, DEBUG, msg, null, null); - } - - @Override - public void debug(String format, Object arg) - { - log(null, DEBUG, format, new Object[]{arg}, null); - } - - @Override - public void debug(String format, Object arg1, Object arg2) - { - log(null, DEBUG, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void debug(String format, Object[] argArray) - { - log(null, DEBUG, format, argArray, null); - } - - @Override - public void debug(String msg, Throwable t) - { - log(null, DEBUG, msg, null, t); - } - - @Override - public void debug(Marker marker, String msg) - { - log(marker, DEBUG, msg, null, null); - } - - @Override - public void debug(Marker marker, String format, Object arg) - { - log(marker, DEBUG, format, new Object[]{arg}, null); - } - - @Override - public void debug(Marker marker, String format, Object arg1, Object arg2) - { - log(marker, DEBUG, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void debug(Marker marker, String format, Object[] argArray) - { - log(marker, DEBUG, format, argArray, null); - } - - @Override - public void debug(Marker marker, String msg, Throwable t) - { - log(marker, DEBUG, msg, null, t); - } - - @Override - public void error(String msg) - { - log(null, ERROR, msg, null, null); - } - - @Override - public void error(String format, Object arg) - { - log(null, ERROR, format, new Object[]{arg}, null); - } - - @Override - public void error(String format, Object arg1, Object arg2) - { - log(null, ERROR, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void error(String format, Object[] argArray) - { - log(null, ERROR, format, argArray, null); - } - - @Override - public void error(String msg, Throwable t) - { - log(null, ERROR, msg, null, t); - } - - @Override - public void error(Marker marker, String msg) - { - log(marker, ERROR, msg, null, null); - } - - @Override - public void error(Marker marker, String format, Object arg) - { - log(marker, ERROR, format, new Object[]{arg}, null); - } - - @Override - public void error(Marker marker, String format, Object arg1, Object arg2) - { - log(marker, ERROR, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void error(Marker marker, String format, Object[] argArray) - { - log(marker, ERROR, format, argArray, null); - } - - @Override - public void error(Marker marker, String msg, Throwable t) - { - log(marker, ERROR, msg, null, t); - } - - @Override - public String getName() - { - return _logger.getName(); - } - - @Override - public void info(String msg) - { - log(null, INFO, msg, null, null); - } - - @Override - public void info(String format, Object arg) - { - log(null, INFO, format, new Object[]{arg}, null); - } - - @Override - public void info(String format, Object arg1, Object arg2) - { - log(null, INFO, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void info(String format, Object[] argArray) - { - log(null, INFO, format, argArray, null); - } - - @Override - public void info(String msg, Throwable t) - { - log(null, INFO, msg, null, t); - } - - @Override - public void info(Marker marker, String msg) - { - log(marker, INFO, msg, null, null); - } - - @Override - public void info(Marker marker, String format, Object arg) - { - log(marker, INFO, format, new Object[]{arg}, null); - } - - @Override - public void info(Marker marker, String format, Object arg1, Object arg2) - { - log(marker, INFO, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void info(Marker marker, String format, Object[] argArray) - { - log(marker, INFO, format, argArray, null); - } - - @Override - public void info(Marker marker, String msg, Throwable t) - { - log(marker, INFO, msg, null, t); - } - - @Override - public boolean isDebugEnabled() - { - return _logger.isDebugEnabled(); - } - - @Override - public boolean isDebugEnabled(Marker marker) - { - return _logger.isDebugEnabled(marker); - } - - @Override - public boolean isErrorEnabled() - { - return _logger.isErrorEnabled(); - } - - @Override - public boolean isErrorEnabled(Marker marker) - { - return _logger.isErrorEnabled(marker); - } - - @Override - public boolean isInfoEnabled() - { - return _logger.isInfoEnabled(); - } - - @Override - public boolean isInfoEnabled(Marker marker) - { - return _logger.isInfoEnabled(marker); - } - - @Override - public boolean isTraceEnabled() - { - return _logger.isTraceEnabled(); - } - - @Override - public boolean isTraceEnabled(Marker marker) - { - return _logger.isTraceEnabled(marker); - } - - @Override - public boolean isWarnEnabled() - { - return _logger.isWarnEnabled(); - } - - @Override - public boolean isWarnEnabled(Marker marker) - { - return _logger.isWarnEnabled(marker); - } - - @Override - public String toString() - { - return _logger.toString(); - } - - @Override - public void trace(String msg) - { - log(null, TRACE, msg, null, null); - } - - @Override - public void trace(String format, Object arg) - { - log(null, TRACE, format, new Object[]{arg}, null); - } - - @Override - public void trace(String format, Object arg1, Object arg2) - { - log(null, TRACE, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void trace(String format, Object[] argArray) - { - log(null, TRACE, format, argArray, null); - } - - @Override - public void trace(String msg, Throwable t) - { - log(null, TRACE, msg, null, t); - } - - @Override - public void trace(Marker marker, String msg) - { - log(marker, TRACE, msg, null, null); - } - - @Override - public void trace(Marker marker, String format, Object arg) - { - log(marker, TRACE, format, new Object[]{arg}, null); - } - - @Override - public void trace(Marker marker, String format, Object arg1, Object arg2) - { - log(marker, TRACE, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void trace(Marker marker, String format, Object[] argArray) - { - log(marker, TRACE, format, argArray, null); - } - - @Override - public void trace(Marker marker, String msg, Throwable t) - { - log(marker, TRACE, msg, null, t); - } - - @Override - public void warn(String msg) - { - log(null, WARN, msg, null, null); - } - - @Override - public void warn(String format, Object arg) - { - log(null, WARN, format, new Object[]{arg}, null); - } - - @Override - public void warn(String format, Object[] argArray) - { - log(null, WARN, format, argArray, null); - } - - @Override - public void warn(String format, Object arg1, Object arg2) - { - log(null, WARN, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void warn(String msg, Throwable t) - { - log(null, WARN, msg, null, t); - } - - @Override - public void warn(Marker marker, String msg) - { - log(marker, WARN, msg, null, null); - } - - @Override - public void warn(Marker marker, String format, Object arg) - { - log(marker, WARN, format, new Object[]{arg}, null); - } - - @Override - public void warn(Marker marker, String format, Object arg1, Object arg2) - { - log(marker, WARN, format, new Object[]{arg1, arg2}, null); - } - - @Override - public void warn(Marker marker, String format, Object[] argArray) - { - log(marker, WARN, format, argArray, null); - } - - @Override - public void warn(Marker marker, String msg, Throwable t) - { - log(marker, WARN, msg, null, t); - } - - private void log(Marker marker, int level, String msg, Object[] argArray, Throwable t) - { - if (argArray == null) - { - // Simple SLF4J Message (no args) - _logger.log(marker, FQCN, level, msg, null, t); - } - else - { - int loggerLevel = _logger.isTraceEnabled() - ? TRACE - : _logger.isDebugEnabled() - ? DEBUG - : _logger.isInfoEnabled() - ? INFO - : _logger.isWarnEnabled() - ? WARN - : ERROR; - if (loggerLevel <= level) - { - // Don't assume downstream handles argArray properly. - // Do it the SLF4J way here to eliminate that as a bug. - FormattingTuple ft = MessageFormatter.arrayFormat(msg, argArray); - _logger.log(marker, FQCN, level, ft.getMessage(), null, t); - } - } - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyLogHandler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyLogHandler.java deleted file mode 100644 index c7cdcf8cf60..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JettyLogHandler.java +++ /dev/null @@ -1,198 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.MessageFormat; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.LogRecord; -import java.util.regex.Pattern; - -/** - * Redirect java.util.logging events to Jetty Log - */ -public class JettyLogHandler extends java.util.logging.Handler -{ - public static void config() - { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("logging.properties"); - if (url != null) - { - System.err.printf("Initializing java.util.logging from %s%n", url); - try (InputStream in = url.openStream()) - { - LogManager.getLogManager().readConfiguration(in); - } - catch (IOException e) - { - e.printStackTrace(System.err); - } - } - else - { - System.err.printf("WARNING: java.util.logging failed to initialize: logging.properties not found%n"); - } - - System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger"); - } - - public JettyLogHandler() - { - if (Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.DEBUG", "false"))) - { - setLevel(Level.FINEST); - } - - if (Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.IGNORED", "false"))) - { - setLevel(Level.ALL); - } - - System.err.printf("%s Initialized at level [%s]%n", this.getClass().getName(), getLevel().getName()); - } - - private synchronized String formatMessage(LogRecord record) - { - String msg = getMessage(record); - - try - { - Object[] params = record.getParameters(); - if ((params == null) || (params.length == 0)) - { - return msg; - } - - if (Pattern.compile("\\{\\d+\\}").matcher(msg).find()) - { - return MessageFormat.format(msg, params); - } - - return msg; - } - catch (Exception ex) - { - return msg; - } - } - - private String getMessage(LogRecord record) - { - ResourceBundle bundle = record.getResourceBundle(); - if (bundle != null) - { - try - { - return bundle.getString(record.getMessage()); - } - catch (java.util.MissingResourceException ignored) - { - } - } - - return record.getMessage(); - } - - @Override - public void publish(LogRecord record) - { - org.eclipse.jetty.util.log.Logger jettyLogger = getJettyLogger(record.getLoggerName()); - - int level = record.getLevel().intValue(); - if (level >= Level.OFF.intValue()) - { - // nothing to log, skip it. - return; - } - - Throwable cause = record.getThrown(); - String msg = formatMessage(record); - - if (level >= Level.WARNING.intValue()) - { - // log at warn - if (cause != null) - { - jettyLogger.warn(msg, cause); - } - else - { - jettyLogger.warn(msg); - } - return; - } - - if (level >= Level.INFO.intValue()) - { - // log at info - if (cause != null) - { - jettyLogger.info(msg, cause); - } - else - { - jettyLogger.info(msg); - } - return; - } - - if (level >= Level.FINEST.intValue()) - { - // log at debug - if (cause != null) - { - jettyLogger.debug(msg, cause); - } - else - { - jettyLogger.debug(msg); - } - return; - } - - if (level >= Level.ALL.intValue()) - { - // only corresponds with ignore (in jetty speak) - jettyLogger.ignore(cause); - return; - } - } - - private Logger getJettyLogger(String loggerName) - { - return org.eclipse.jetty.util.log.Log.getLogger(loggerName); - } - - @Override - public void flush() - { - // ignore - } - - @Override - public void close() throws SecurityException - { - // ignore - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java index 756076c2743..2491f058438 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java @@ -18,296 +18,45 @@ package org.eclipse.jetty.util.log; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.eclipse.jetty.util.Loader; -import org.eclipse.jetty.util.Uptime; -import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.slf4j.LoggerFactory; /** - * Logging. - * This class provides a static logging interface. If an instance of the - * org.slf4j.Logger class is found on the classpath, the static log methods - * are directed to a slf4j logger for "org.eclipse.log". Otherwise the logs - * are directed to stderr. - *

- * The "org.eclipse.jetty.util.log.class" system property can be used - * to select a specific logging implementation. - *

- * If the system property org.eclipse.jetty.util.log.IGNORED is set, - * then ignored exceptions are logged in detail. + * Legacy bridge API to Slf4j * - * @see StdErrLog - * @see Slf4jLog + * @deprecated */ public class Log { - public static final String EXCEPTION = "EXCEPTION "; - public static final String IGNORED = "IGNORED EXCEPTION "; - /** - * The {@link Logger} implementation class name - */ - public static String __logClass; - /** - * Legacy flag indicating if {@link Logger#ignore(Throwable)} methods produce any output in the {@link Logger}s - */ - public static boolean __ignored; - /** - * Logging Configuration Properties - */ - protected static final Properties PROPS = new Properties(); - private static final ConcurrentMap LOGGERS = new ConcurrentHashMap<>(); - private static boolean __initialized; - private static Logger LOG; + @Deprecated + public static final String EXCEPTION = "EXCEPTION"; - static + @Deprecated + public static org.eclipse.jetty.util.log.Logger getLogger(Class clazz) { - AccessController.doPrivileged(new PrivilegedAction() - { - @Override - public Object run() - { - // First see if the jetty-logging.properties object exists in the classpath. - // * This is an optional feature used by embedded mode use, and test cases to allow for early - // * configuration of the Log class in situations where access to the System.properties are - // * either too late or just impossible. - loadProperties("jetty-logging.properties", PROPS); - - // Next see if an OS specific jetty-logging.properties object exists in the classpath. - // This really for setting up test specific logging behavior based on OS. - String osName = System.getProperty("os.name"); - if (osName != null && osName.length() > 0) - { - // NOTE: cannot use jetty-util's StringUtil.replace() as it may initialize logging itself. - osName = osName.toLowerCase(Locale.ENGLISH).replace(' ', '-'); - loadProperties("jetty-logging-" + osName + ".properties", PROPS); - } - - // Now load the System.properties as-is into the __props, - // these values will override any key conflicts in __props. - @SuppressWarnings("unchecked") - Enumeration systemKeyEnum = (Enumeration)System.getProperties().propertyNames(); - while (systemKeyEnum.hasMoreElements()) - { - String key = systemKeyEnum.nextElement(); - String val = System.getProperty(key); - // Protect against application code insertion of non-String values (returned as null). - if (val != null) - PROPS.setProperty(key, val); - } - - // Now use the configuration properties to configure the Log statics. - __logClass = PROPS.getProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog"); - __ignored = Boolean.parseBoolean(PROPS.getProperty("org.eclipse.jetty.util.log.IGNORED", "false")); - return null; - } - }); + return new Slf4jLogger(LoggerFactory.getLogger(clazz)); } - private static void loadProperties(String resourceName, Properties props) + @Deprecated + public static org.eclipse.jetty.util.log.Logger getLogger(String name) { - URL testProps = Loader.getResource(resourceName); - if (testProps != null) - { - try (InputStream in = testProps.openStream()) - { - Properties p = new Properties(); - p.load(in); - for (Object key : p.keySet()) - { - Object value = p.get(key); - if (value != null) - props.put(key, value); - } - } - catch (IOException e) - { - System.err.println("[WARN] Error loading logging config: " + testProps); - e.printStackTrace(); - } - } + return new Slf4jLogger(LoggerFactory.getLogger(name)); } - public static void initialized() + @Deprecated + public static org.eclipse.jetty.util.log.Logger getRootLogger() { - synchronized (Log.class) - { - if (__initialized) - return; - __initialized = true; - - boolean announce = Boolean.parseBoolean(PROPS.getProperty("org.eclipse.jetty.util.log.announce", "true")); - try - { - Class logClass = Loader.loadClass(Log.class, __logClass); - if (LOG == null || !LOG.getClass().equals(logClass)) - { - LOG = (Logger)logClass.getDeclaredConstructor().newInstance(); - if (announce) - LOG.debug("Logging to {} via {}", LOG, logClass.getName()); - } - } - catch (Throwable e) - { - // Unable to load specified Logger implementation, default to standard logging. - initStandardLogging(e); - } - - if (announce && LOG != null) - LOG.info(String.format("Logging initialized @%dms to %s", Uptime.getUptime(), LOG.getClass().getName())); - } + return new Slf4jLogger(LoggerFactory.getLogger("")); } - private static void initStandardLogging(Throwable e) + @Deprecated + public static org.eclipse.jetty.util.log.Logger getLog() { - if (__ignored) - e.printStackTrace(); - - if (LOG == null) - LOG = new StdErrLog(); + return getRootLogger(); } - public static Logger getLog() + @Deprecated + public static void setLog(org.eclipse.jetty.util.log.Logger log) { - initialized(); - return LOG; - } - - /** - * Set the root logger. - *

- * Note that if any classes have statically obtained their logger instance prior to this call, their Logger will not - * be affected by this call. - * - * @param log the root logger implementation to set - */ - public static void setLog(Logger log) - { - Log.LOG = log; - __logClass = null; - } - - /** - * Get the root logger. - * - * @return the root logger - */ - public static Logger getRootLogger() - { - initialized(); - return LOG; - } - - static boolean isIgnored() - { - return __ignored; - } - - /** - * Set Log to parent Logger. - *

- * If there is a different Log class available from a parent classloader, - * call {@link #getLogger(String)} on it and construct a {@link LoggerLog} instance - * as this Log's Logger, so that logging is delegated to the parent Log. - *

- * This should be used if a webapp is using Log, but wishes the logging to be - * directed to the containers log. - *

- * If there is not parent Log, then this call is equivalent to

-     *   Log.setLog(Log.getLogger(name));
-     * 
- * - * @param name Logger name - */ - public static void setLogToParent(String name) - { - ClassLoader loader = Log.class.getClassLoader(); - if (loader != null && loader.getParent() != null) - { - try - { - Class uberlog = loader.getParent().loadClass("org.eclipse.jetty.util.log.Log"); - Method getLogger = uberlog.getMethod("getLogger", new Class[]{String.class}); - Object logger = getLogger.invoke(null, name); - setLog(new LoggerLog(logger)); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - else - { - setLog(getLogger(name)); - } - } - - /** - * Obtain a named Logger based on the fully qualified class name. - * - * @param clazz the class to base the Logger name off of - * @return the Logger with the given name - */ - public static Logger getLogger(Class clazz) - { - return getLogger(clazz.getName()); - } - - /** - * Obtain a named Logger or the default Logger if null is passed. - * - * @param name the Logger name - * @return the Logger with the given name - */ - public static Logger getLogger(String name) - { - initialized(); - - if (name == null) - return LOG; - - Logger logger = LOGGERS.get(name); - if (logger == null) - logger = LOG.getLogger(name); - - return logger; - } - - static ConcurrentMap getMutableLoggers() - { - return LOGGERS; - } - - /** - * Get a map of all configured {@link Logger} instances. - * - * @return a map of all configured {@link Logger} instances - */ - @ManagedAttribute("list of all instantiated loggers") - public static Map getLoggers() - { - return Collections.unmodifiableMap(LOGGERS); - } - - public static Properties getProperties() - { - return PROPS; - } - - public static String getProperty(String key, String defaultValue) - { - return PROPS.getProperty(key, defaultValue); + // does nothing } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java index 6def16bb013..928d30507fe 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java @@ -19,8 +19,11 @@ package org.eclipse.jetty.util.log; /** - * A simple logging facade that is intended simply to capture the style of logging as used by Jetty. + * Legacy Bridge API to Slf4j + * + * @deprecated */ +@Deprecated public interface Logger { /** diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java deleted file mode 100644 index 5cc57fcdb48..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java +++ /dev/null @@ -1,243 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.lang.reflect.Method; - -/** - * - */ -public class LoggerLog extends AbstractLogger -{ - private final Object _logger; - private final Method _debugMT; - private final Method _debugMAA; - private final Method _infoMT; - private final Method _infoMAA; - private final Method _warnMT; - private final Method _warnMAA; - private final Method _setDebugEnabledE; - private final Method _getLoggerN; - private final Method _getName; - private volatile boolean _debug; - - public LoggerLog(Object logger) - { - try - { - _logger = logger; - final Class lc = logger.getClass(); - _debugMT = lc.getMethod("debug", new Class[]{String.class, Throwable.class}); - _debugMAA = lc.getMethod("debug", new Class[]{String.class, Object[].class}); - _infoMT = lc.getMethod("info", new Class[]{String.class, Throwable.class}); - _infoMAA = lc.getMethod("info", new Class[]{String.class, Object[].class}); - _warnMT = lc.getMethod("warn", new Class[]{String.class, Throwable.class}); - _warnMAA = lc.getMethod("warn", new Class[]{String.class, Object[].class}); - final Method isDebugEnabled = lc.getMethod("isDebugEnabled"); - _setDebugEnabledE = lc.getMethod("setDebugEnabled", new Class[]{Boolean.TYPE}); - _getLoggerN = lc.getMethod("getLogger", new Class[]{String.class}); - _getName = lc.getMethod("getName"); - - _debug = (Boolean)isDebugEnabled.invoke(_logger); - } - catch (Exception x) - { - throw new IllegalStateException(x); - } - } - - @Override - public String getName() - { - try - { - return (String)_getName.invoke(_logger); - } - catch (Exception e) - { - e.printStackTrace(); - return null; - } - } - - @Override - public void warn(String msg, Object... args) - { - try - { - _warnMAA.invoke(_logger, args); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void warn(Throwable thrown) - { - warn("", thrown); - } - - @Override - public void warn(String msg, Throwable thrown) - { - try - { - _warnMT.invoke(_logger, msg, thrown); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void info(String msg, Object... args) - { - try - { - _infoMAA.invoke(_logger, args); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void info(Throwable thrown) - { - info("", thrown); - } - - @Override - public void info(String msg, Throwable thrown) - { - try - { - _infoMT.invoke(_logger, msg, thrown); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public boolean isDebugEnabled() - { - return _debug; - } - - @Override - public void setDebugEnabled(boolean enabled) - { - try - { - _setDebugEnabledE.invoke(_logger, enabled); - _debug = enabled; - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void debug(String msg, Object... args) - { - if (!_debug) - return; - - try - { - _debugMAA.invoke(_logger, args); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void debug(Throwable thrown) - { - debug("", thrown); - } - - @Override - public void debug(String msg, Throwable th) - { - if (!_debug) - return; - - try - { - _debugMT.invoke(_logger, msg, th); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void debug(String msg, long value) - { - if (!_debug) - return; - - try - { - _debugMAA.invoke(_logger, new Object[]{value}); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void ignore(Throwable ignored) - { - if (Log.isIgnored()) - { - debug(Log.IGNORED, ignored); - } - } - - /** - * Create a Child Logger of this Logger. - */ - @Override - protected Logger newLogger(String fullname) - { - try - { - Object logger = _getLoggerN.invoke(_logger, fullname); - return new LoggerLog(logger); - } - catch (Exception e) - { - e.printStackTrace(); - return this; - } - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java deleted file mode 100644 index 51a5cfc618f..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java +++ /dev/null @@ -1,152 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -/** - * Slf4jLog Logger - */ -public class Slf4jLog extends AbstractLogger -{ - private final org.slf4j.Logger _logger; - - public Slf4jLog() throws Exception - { - this("org.eclipse.jetty.util.log"); - } - - public Slf4jLog(String name) - { - //NOTE: if only an slf4j-api jar is on the classpath, slf4j will use a NOPLogger - org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(name); - - // Fix LocationAwareLogger use to indicate FQCN of this class - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670 - if (logger instanceof org.slf4j.spi.LocationAwareLogger) - { - _logger = new JettyAwareLogger((org.slf4j.spi.LocationAwareLogger)logger); - } - else - { - _logger = logger; - } - } - - @Override - public String getName() - { - return _logger.getName(); - } - - @Override - public void warn(String msg, Object... args) - { - _logger.warn(msg, args); - } - - @Override - public void warn(Throwable thrown) - { - warn("", thrown); - } - - @Override - public void warn(String msg, Throwable thrown) - { - _logger.warn(msg, thrown); - } - - @Override - public void info(String msg, Object... args) - { - _logger.info(msg, args); - } - - @Override - public void info(Throwable thrown) - { - info("", thrown); - } - - @Override - public void info(String msg, Throwable thrown) - { - _logger.info(msg, thrown); - } - - @Override - public void debug(String msg, Object... args) - { - _logger.debug(msg, args); - } - - @Override - public void debug(String msg, long arg) - { - if (isDebugEnabled()) - _logger.debug(msg, new Object[]{arg}); - } - - @Override - public void debug(Throwable thrown) - { - debug("", thrown); - } - - @Override - public void debug(String msg, Throwable thrown) - { - _logger.debug(msg, thrown); - } - - @Override - public boolean isDebugEnabled() - { - return _logger.isDebugEnabled(); - } - - @Override - public void setDebugEnabled(boolean enabled) - { - warn("setDebugEnabled not implemented", null, null); - } - - /** - * Create a Child Logger of this Logger. - */ - @Override - protected Logger newLogger(String fullname) - { - return new Slf4jLog(fullname); - } - - @Override - public void ignore(Throwable ignored) - { - if (Log.isIgnored()) - { - debug(Log.IGNORED, ignored); - } - } - - @Override - public String toString() - { - return _logger.toString(); - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLogger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLogger.java new file mode 100644 index 00000000000..95d966ba856 --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLogger.java @@ -0,0 +1,123 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.util.log; + +import org.slf4j.LoggerFactory; + +@Deprecated +class Slf4jLogger implements org.eclipse.jetty.util.log.Logger +{ + private final org.slf4j.Logger logger; + + Slf4jLogger(org.slf4j.Logger logger) + { + this.logger = logger; + } + + @Override + public void debug(String format, Object... args) + { + logger.debug(format, args); + } + + @Override + public void debug(String msg, long value) + { + logger.debug(msg, value); + } + + @Override + public void debug(Throwable cause) + { + logger.debug(cause.getMessage(), cause); + } + + @Override + public void debug(String msg, Throwable thrown) + { + logger.debug(msg, thrown); + } + + @Override + public org.eclipse.jetty.util.log.Logger getLogger(String name) + { + return new Slf4jLogger(LoggerFactory.getLogger(getName() + name)); + } + + @Override + public void ignore(Throwable cause) + { + logger.trace("IGNORED", cause); + } + + @Override + public void info(String format, Object... args) + { + logger.info(format, args); + } + + @Override + public void info(Throwable cause) + { + logger.info(cause.getMessage(), cause); + } + + @Override + public void info(String msg, Throwable thrown) + { + logger.info(msg, thrown); + } + + @Override + public boolean isDebugEnabled() + { + return logger.isDebugEnabled(); + } + + @Override + @Deprecated + public void setDebugEnabled(boolean enabled) + { + // NOT SUPPORTED + } + + @Override + public void warn(Throwable cause) + { + logger.warn(cause.getMessage(), cause); + } + + @Override + public void warn(String msg, Throwable cause) + { + logger.warn(msg, cause); + } + + @Override + public String getName() + { + return logger.getName(); + } + + @Override + public void warn(String format, Object... args) + { + logger.warn(format, args); + } +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java deleted file mode 100644 index d51bba04a0e..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java +++ /dev/null @@ -1,86 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.util.HashSet; -import java.util.Set; - -/** - * A try-with-resources compatible layer for {@link StdErrLog#setHideStacks(boolean) hiding stacktraces} within the scope of the try block when - * logging with {@link StdErrLog} implementation. - *

- * Use of other logging implementation cause no effect when using this class - *

- * Example: - * - *

- * try (StacklessLogging scope = new StacklessLogging(EventDriver.class,Noisy.class))
- * {
- *     doActionThatCausesStackTraces();
- * }
- * 
- */ -public class StacklessLogging implements AutoCloseable -{ - private final Set squelched = new HashSet<>(); - - public StacklessLogging(Class... classesToSquelch) - { - for (Class clazz : classesToSquelch) - { - Logger log = Log.getLogger(clazz); - // only operate on loggers that are of type StdErrLog - if (log instanceof StdErrLog && !log.isDebugEnabled()) - { - StdErrLog stdErrLog = ((StdErrLog)log); - if (!stdErrLog.isHideStacks()) - { - stdErrLog.setHideStacks(true); - squelched.add(stdErrLog); - } - } - } - } - - public StacklessLogging(Logger... logs) - { - for (Logger log : logs) - { - // only operate on loggers that are of type StdErrLog - if (log instanceof StdErrLog && !log.isDebugEnabled()) - { - StdErrLog stdErrLog = ((StdErrLog)log); - if (!stdErrLog.isHideStacks()) - { - stdErrLog.setHideStacks(true); - squelched.add(stdErrLog); - } - } - } - } - - @Override - public void close() - { - for (StdErrLog log : squelched) - { - log.setHideStacks(false); - } - } -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java deleted file mode 100644 index b1dc543745c..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ /dev/null @@ -1,688 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.PrintStream; -import java.security.AccessControlException; -import java.util.Properties; - -import org.eclipse.jetty.util.DateCache; -import org.eclipse.jetty.util.annotation.ManagedAttribute; -import org.eclipse.jetty.util.annotation.ManagedObject; - -/** - * StdErr Logging implementation. - *

- * A Jetty {@link Logger} that sends all logs to STDERR ({@link System#err}) with basic formatting. - *

- * Supports named loggers, and properties based configuration. - *

- * Configuration Properties: - *

- *
${name|hierarchy}.LEVEL=(ALL|DEBUG|INFO|WARN|OFF)
- *
- * Sets the level that the Logger should log at.
- * Names can be a package name, or a fully qualified class name.
- * Default: INFO
- *
- * Examples: - *
- *
org.eclipse.jetty.LEVEL=WARN
- *
indicates that all of the jetty specific classes, in any package that - * starts with org.eclipse.jetty should log at level WARN.
- *
org.eclipse.jetty.io.ChannelEndPoint.LEVEL=ALL
- *
indicates that the specific class, ChannelEndPoint, should log all - * logging events that it can generate, including DEBUG, INFO, WARN (and even special - * internally ignored exception cases).
- *
- *
- * - *
${name}.SOURCE=(true|false)
- *
- * Logger specific, attempt to print the java source file name and line number - * where the logging event originated from.
- * Name must be a fully qualified class name (package name hierarchy is not supported - * by this configurable)
- * Warning: this is a slow operation and will have an impact on performance!
- * Default: false - *
- * - *
${name}.STACKS=(true|false)
- *
- * Logger specific, control the display of stacktraces.
- * Name must be a fully qualified class name (package name hierarchy is not supported - * by this configurable)
- * Default: true - *
- * - *
org.eclipse.jetty.util.log.stderr.SOURCE=(true|false)
- *
Special Global Configuration, attempt to print the java source file name and line number - * where the logging event originated from.
- * Default: false - *
- * - *
org.eclipse.jetty.util.log.stderr.LONG=(true|false)
- *
Special Global Configuration, when true, output logging events to STDERR using - * long form, fully qualified class names. when false, use abbreviated package names
- * Default: false - *
- *
org.eclipse.jetty.util.log.stderr.ESCAPE=(true|false)
- *
Global Configuration, when true output logging events to STDERR are always - * escaped so that control characters are replaced with '?"; '\r' with '<' and '\n' replaced '|'
- * Default: true - *
- *
- */ -@ManagedObject("Jetty StdErr Logging Implementation") -public class StdErrLog extends AbstractLogger -{ - private static final String EOL = System.lineSeparator(); - private static final Object[] EMPTY_ARGS = new Object[0]; - // Do not change output format lightly, people rely on this output format now. - private static int __threadNamePadding = Integer.parseInt(Log.getProperty("org.eclipse.jetty.util.log.StdErrLog.TAG_PAD", "0")); - private static DateCache _dateCache; - - private static final boolean SOURCE = Boolean.parseBoolean( - Log.getProperty("org.eclipse.jetty.util.log.SOURCE", - Log.getProperty("org.eclipse.jetty.util.log.stderr.SOURCE", "false"))); - private static final boolean LONG_CLASSNAMES = Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.stderr.LONG", "false")); - private static final boolean ESCAPE_CONTROL_CHARS = Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.stderr.ESCAPE", "true")); - - static - { - try - { - _dateCache = new DateCache("yyyy-MM-dd HH:mm:ss"); - } - catch (Exception x) - { - x.printStackTrace(System.err); - } - } - - public static void setTagPad(int pad) - { - __threadNamePadding = pad; - } - - private int _level; - // Level that this Logger was configured as (remembered in special case of .setDebugEnabled()) - private int _configuredLevel; - // The alternate stream to print to (if set) - private PrintStream _altStream; - private boolean _source; - // Print the long form names, otherwise use abbreviated - private boolean _printLongNames = LONG_CLASSNAMES; - // The full log name, as provided by the system. - private final String _name; - // The abbreviated log name (used by default, unless _printLongNames is specified) - protected final String _abbrevname; - private boolean _hideStacks = false; - - public static int getLoggingLevel(Properties props, String name) - { - int level = lookupLoggingLevel(props, name); - if (level == LEVEL_DEFAULT) - { - level = lookupLoggingLevel(props, "log"); - if (level == LEVEL_DEFAULT) - level = LEVEL_INFO; - } - return level; - } - - /** - * Obtain a StdErrLog reference for the specified class, a convenience method used most often during testing to allow for control over a specific logger. - *

- * Must be actively using StdErrLog as the Logger implementation. - * - * @param clazz the Class reference for the logger to use. - * @return the StdErrLog logger - * @throws RuntimeException if StdErrLog is not the active Logger implementation. - */ - public static StdErrLog getLogger(Class clazz) - { - Logger log = Log.getLogger(clazz); - if (log instanceof StdErrLog) - { - return (StdErrLog)log; - } - throw new RuntimeException("Logger for " + clazz + " is not of type StdErrLog"); - } - - /** - * Construct an anonymous StdErrLog (no name). - *

- * NOTE: Discouraged usage! - */ - public StdErrLog() - { - this(null); - } - - /** - * Construct a named StdErrLog using the {@link Log} defined properties - * - * @param name the name of the logger - */ - public StdErrLog(String name) - { - this(name, null); - } - - /** - * Construct a named Logger using the provided properties to configure logger. - * - * @param name the name of the logger - * @param props the configuration properties - */ - public StdErrLog(String name, Properties props) - { - @SuppressWarnings("ReferenceEquality") - boolean sameObject = (props != Log.PROPS); - if (props != null && sameObject) - Log.PROPS.putAll(props); - _name = name == null ? "" : name; - _abbrevname = condensePackageString(this._name); - _level = getLoggingLevel(Log.PROPS, this._name); - _configuredLevel = _level; - - try - { - String source = getLoggingProperty(Log.PROPS, _name, "SOURCE"); - _source = source == null ? SOURCE : Boolean.parseBoolean(source); - } - catch (AccessControlException ace) - { - _source = SOURCE; - } - - try - { - // allow stacktrace display to be controlled by properties as well - String stacks = getLoggingProperty(Log.PROPS, _name, "STACKS"); - _hideStacks = stacks != null && !Boolean.parseBoolean(stacks); - } - catch (AccessControlException ignore) - { - /* ignore */ - } - } - - @Override - public String getName() - { - return _name; - } - - public void setPrintLongNames(boolean printLongNames) - { - this._printLongNames = printLongNames; - } - - public boolean isPrintLongNames() - { - return this._printLongNames; - } - - public boolean isHideStacks() - { - return _hideStacks; - } - - public void setHideStacks(boolean hideStacks) - { - _hideStacks = hideStacks; - } - - /** - * Is the source of a log, logged - * - * @return true if the class, method, file and line number of a log is logged. - */ - public boolean isSource() - { - return _source; - } - - /** - * Set if a log source is logged. - * - * @param source true if the class, method, file and line number of a log is logged. - */ - public void setSource(boolean source) - { - _source = source; - } - - @Override - public void warn(String msg, Object... args) - { - if (_level <= LEVEL_WARN) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":WARN:", msg, args); - println(builder); - } - } - - @Override - public void warn(Throwable thrown) - { - warn("", thrown); - } - - @Override - public void warn(String msg, Throwable thrown) - { - if (_level <= LEVEL_WARN) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":WARN:", msg, thrown); - println(builder); - } - } - - @Override - public void info(String msg, Object... args) - { - if (_level <= LEVEL_INFO) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":INFO:", msg, args); - println(builder); - } - } - - @Override - public void info(Throwable thrown) - { - info("", thrown); - } - - @Override - public void info(String msg, Throwable thrown) - { - if (_level <= LEVEL_INFO) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":INFO:", msg, thrown); - println(builder); - } - } - - @ManagedAttribute("is debug enabled for root logger Log.LOG") - @Override - public boolean isDebugEnabled() - { - return (_level <= LEVEL_DEBUG); - } - - /** - * Legacy interface where a programmatic configuration of the logger level - * is done as a wholesale approach. - */ - @Override - public void setDebugEnabled(boolean enabled) - { - int level = enabled ? LEVEL_DEBUG : this.getConfiguredLevel(); - this.setLevel(level); - - String name = getName(); - for (Logger log : Log.getLoggers().values()) - { - if (log.getName().startsWith(name) && log instanceof StdErrLog) - { - StdErrLog logger = (StdErrLog)log; - level = enabled ? LEVEL_DEBUG : logger.getConfiguredLevel(); - logger.setLevel(level); - } - } - } - - private int getConfiguredLevel() - { - return _configuredLevel; - } - - public int getLevel() - { - return _level; - } - - /** - * Set the level for this logger. - *

- * Available values ({@link StdErrLog#LEVEL_ALL}, {@link StdErrLog#LEVEL_DEBUG}, {@link StdErrLog#LEVEL_INFO}, - * {@link StdErrLog#LEVEL_WARN}) - * - * @param level the level to set the logger to - */ - public void setLevel(int level) - { - this._level = level; - } - - /** - * The alternate stream to use for STDERR. - * - * @param stream the stream of choice, or {@code null} to use {@link System#err} - */ - public void setStdErrStream(PrintStream stream) - { - this._altStream = stream; - } - - @Override - public void debug(String msg, Object... args) - { - if (isDebugEnabled()) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":DBUG:", msg, args); - println(builder); - } - } - - @Override - public void debug(String msg, long arg) - { - if (isDebugEnabled()) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":DBUG:", msg, arg); - println(builder); - } - } - - @Override - public void debug(Throwable thrown) - { - debug("", thrown); - } - - @Override - public void debug(String msg, Throwable thrown) - { - if (isDebugEnabled()) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":DBUG:", msg, thrown); - println(builder); - } - } - - private void println(StringBuilder builder) - { - if (_altStream != null) - _altStream.println(builder); - else - { - // We always use the PrintStream stored in System.err, - // just in case someone has replaced it with a call to System.setErr(PrintStream) - System.err.println(builder); - } - } - - private void format(StringBuilder builder, String level, String msg, Object... inArgs) - { - long now = System.currentTimeMillis(); - int ms = (int)(now % 1000); - String d = _dateCache.formatNow(now); - tag(builder, d, ms, level); - - Object[] msgArgs = EMPTY_ARGS; - int msgArgsLen = 0; - Throwable cause = null; - - if (inArgs != null) - { - msgArgs = inArgs; - msgArgsLen = inArgs.length; - if (msgArgsLen > 0 && inArgs[msgArgsLen - 1] instanceof Throwable) - { - cause = (Throwable)inArgs[msgArgsLen - 1]; - msgArgsLen--; - } - } - - if (msg == null) - { - msg = "{} ".repeat(msgArgsLen); - } - String braces = "{}"; - int start = 0; - for (int i = 0; i < msgArgsLen; i++) - { - Object arg = msgArgs[i]; - int bracesIndex = msg.indexOf(braces, start); - if (bracesIndex < 0) - { - escape(builder, msg.substring(start)); - builder.append(" "); - if (arg != null) - builder.append(arg); - start = msg.length(); - } - else - { - escape(builder, msg.substring(start, bracesIndex)); - if (arg != null) - builder.append(arg); - start = bracesIndex + braces.length(); - } - } - escape(builder, msg.substring(start)); - - if (cause != null) - { - if (isHideStacks()) - { - builder.append(": ").append(cause); - } - else - { - formatCause(builder, cause, ""); - } - } - } - - private void formatCause(StringBuilder builder, Throwable cause, String indent) - { - builder.append(EOL).append(indent); - escape(builder, cause.toString()); - StackTraceElement[] elements = cause.getStackTrace(); - for (int i = 0; elements != null && i < elements.length; i++) - { - builder.append(EOL).append(indent).append("\tat "); - escape(builder, elements[i].toString()); - } - - for (Throwable suppressed : cause.getSuppressed()) - { - builder.append(EOL).append(indent).append("Suppressed: "); - formatCause(builder, suppressed, "\t|" + indent); - } - - Throwable by = cause.getCause(); - if (by != null && by != cause) - { - builder.append(EOL).append(indent).append("Caused by: "); - formatCause(builder, by, indent); - } - } - - private void escape(StringBuilder builder, String str) - { - if (ESCAPE_CONTROL_CHARS) - { - for (int i = 0; i < str.length(); ++i) - { - char c = str.charAt(i); - if (Character.isISOControl(c)) - { - if (c == '\n') - { - builder.append('|'); - } - else if (c == '\r') - { - builder.append('<'); - } - else - { - builder.append('?'); - } - } - else - { - builder.append(c); - } - } - } - else - builder.append(str); - } - - private void tag(StringBuilder builder, String d, int ms, String tag) - { - builder.setLength(0); - builder.append(d); - if (ms > 99) - { - builder.append('.'); - } - else if (ms > 9) - { - builder.append(".0"); - } - else - { - builder.append(".00"); - } - builder.append(ms).append(tag); - - String name = _printLongNames ? _name : _abbrevname; - String tname = Thread.currentThread().getName(); - - int p = __threadNamePadding > 0 ? (name.length() + tname.length() - __threadNamePadding) : 0; - - if (p < 0) - { - builder - .append(name) - .append(':') - .append(" ", 0, -p) - .append(tname); - } - else if (p == 0) - { - builder.append(name).append(':').append(tname); - } - builder.append(':'); - - if (_source) - { - Throwable source = new Throwable(); - StackTraceElement[] frames = source.getStackTrace(); - for (final StackTraceElement frame : frames) - { - String clazz = frame.getClassName(); - if (clazz.equals(StdErrLog.class.getName()) || clazz.equals(Log.class.getName())) - { - continue; - } - if (!_printLongNames && clazz.startsWith("org.eclipse.jetty.")) - { - builder.append(condensePackageString(clazz)); - } - else - { - builder.append(clazz); - } - builder.append('#').append(frame.getMethodName()); - if (frame.getFileName() != null) - { - builder.append('(').append(frame.getFileName()).append(':').append(frame.getLineNumber()).append(')'); - } - builder.append(':'); - break; - } - } - - builder.append(' '); - } - - /** - * Create a Child Logger of this Logger. - */ - @Override - protected Logger newLogger(String fullname) - { - StdErrLog logger = new StdErrLog(fullname); - // Preserve configuration for new loggers configuration - logger.setPrintLongNames(_printLongNames); - logger._altStream = this._altStream; - - // Force the child to have any programmatic configuration - if (_level != _configuredLevel) - logger._level = _level; - - return logger; - } - - @Override - public String toString() - { - StringBuilder s = new StringBuilder(); - s.append("StdErrLog:"); - s.append(_name); - s.append(":LEVEL="); - switch (_level) - { - case LEVEL_ALL: - s.append("ALL"); - break; - case LEVEL_DEBUG: - s.append("DEBUG"); - break; - case LEVEL_INFO: - s.append("INFO"); - break; - case LEVEL_WARN: - s.append("WARN"); - break; - default: - s.append("?"); - break; - } - return s.toString(); - } - - @Override - public void ignore(Throwable ignored) - { - if (_level <= LEVEL_ALL) - { - StringBuilder builder = new StringBuilder(64); - format(builder, ":IGNORED:", "", ignored); - println(builder); - } - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java index e9f16cba8c4..8e0f7656391 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.util.component; import java.util.concurrent.TimeUnit; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Blue.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Blue.java deleted file mode 100644 index ee1409610d9..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Blue.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -public class Blue -{ - private static final Logger LOG = Log.getLogger(Blue.class); - - public void generateLogs() - { - LOG.debug("My color is {}", Blue.class.getSimpleName()); - LOG.info("I represent the emotion Admiration"); - LOG.warn("I can also mean Disgust"); - LOG.ignore(new RuntimeException("Yawn")); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java deleted file mode 100644 index bb6c4267c2f..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/CapturingJULHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.Handler; -import java.util.logging.LogRecord; - -import org.eclipse.jetty.util.IO; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; - -public class CapturingJULHandler extends Handler -{ - private static final String LN = System.getProperty("line.separator"); - private StringBuilder output = new StringBuilder(); - - @Override - public void publish(LogRecord record) - { - StringBuilder buf = new StringBuilder(); - buf.append(record.getLevel().getName()).append("|"); - buf.append(record.getLoggerName()).append("|"); - buf.append(record.getMessage()); - - output.append(buf); - if (record.getMessage().length() > 0) - { - output.append(LN); - } - - if (record.getThrown() != null) - { - StringWriter sw = new StringWriter(128); - PrintWriter capture = new PrintWriter(sw); - record.getThrown().printStackTrace(capture); - capture.flush(); - output.append(sw.toString()); - IO.close(capture); - } - } - - public void clear() - { - output.setLength(0); - } - - @Override - public void flush() - { - /* do nothing */ - } - - @Override - public void close() throws SecurityException - { - /* do nothing */ - } - - public void dump() - { - System.out.println(output); - } - - public void assertContainsLine(String line) - { - assertThat(output.toString(), containsString(line)); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Green.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Green.java deleted file mode 100644 index fb929ee7987..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Green.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -public class Green -{ - private static final Logger LOG = Log.getLogger(Green.class); - - public void generateLogs() - { - LOG.debug("My color is {}", Green.class.getSimpleName()); - LOG.info("I represent the emotion Trust"); - LOG.warn("I can also mean Fear"); - LOG.ignore(new RuntimeException("Ick")); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java deleted file mode 100644 index 2d8d1a655b2..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/JavaUtilLogTest.java +++ /dev/null @@ -1,243 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogManager; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -public class JavaUtilLogTest -{ - private static Handler[] originalHandlers; - private static CapturingJULHandler jul; - - @BeforeAll - public static void setJUL() - { - LogManager lmgr = LogManager.getLogManager(); - java.util.logging.Logger root = lmgr.getLogger(""); - // Remember original handlers - originalHandlers = root.getHandlers(); - // Remove original handlers - for (Handler existing : originalHandlers) - { - root.removeHandler(existing); - } - // Set test/capturing handler - jul = new CapturingJULHandler(); - root.addHandler(jul); - } - - @AfterAll - public static void restoreJUL() - { - LogManager lmgr = LogManager.getLogManager(); - java.util.logging.Logger root = lmgr.getLogger(""); - // Remove test handlers - for (Handler existing : root.getHandlers()) - { - root.removeHandler(existing); - } - // Restore original handlers - for (Handler original : originalHandlers) - { - root.addHandler(original); - } - } - - @Test - public void testNamedLogger() - { - jul.clear(); - JavaUtilLog log = new JavaUtilLog("test"); - log.info("Info test"); - - jul.assertContainsLine("INFO|test|Info test"); - - JavaUtilLog loglong = new JavaUtilLog("test.a.long.name"); - loglong.info("Long test"); - - jul.assertContainsLine("INFO|test.a.long.name|Long test"); - } - - @Test - public void testDebugOutput() - { - jul.clear(); - - // Common Throwable (for test) - Throwable th = new Throwable("Message"); - - // Capture raw string form - StringWriter tout = new StringWriter(); - th.printStackTrace(new PrintWriter(tout)); - String ths = tout.toString(); - - // Tests - JavaUtilLog log = new JavaUtilLog("test.de.bug"); - setJulLevel("test.de.bug", Level.FINE); - - log.debug("Simple debug"); - log.debug("Debug with {} parameter", 1); - log.debug("Debug with {} {} parameters", 2, "spiffy"); - log.debug("Debug with throwable", th); - log.debug(th); - - // jul.dump(); - - jul.assertContainsLine("FINE|test.de.bug|Simple debug"); - jul.assertContainsLine("FINE|test.de.bug|Debug with 1 parameter"); - jul.assertContainsLine("FINE|test.de.bug|Debug with 2 spiffy parameters"); - jul.assertContainsLine("FINE|test.de.bug|Debug with throwable"); - jul.assertContainsLine(ths); - } - - @Test - public void testInfoOutput() - { - jul.clear(); - - // Common Throwable (for test) - Throwable th = new Throwable("Message"); - - // Capture raw string form - StringWriter tout = new StringWriter(); - th.printStackTrace(new PrintWriter(tout)); - String ths = tout.toString(); - - // Tests - JavaUtilLog log = new JavaUtilLog("test.in.fo"); - setJulLevel("test.in.fo", Level.INFO); - - log.info("Simple info"); - log.info("Info with {} parameter", 1); - log.info("Info with {} {} parameters", 2, "spiffy"); - log.info("Info with throwable", th); - log.info(th); - - // jul.dump(); - - jul.assertContainsLine("INFO|test.in.fo|Simple info"); - jul.assertContainsLine("INFO|test.in.fo|Info with 1 parameter"); - jul.assertContainsLine("INFO|test.in.fo|Info with 2 spiffy parameters"); - jul.assertContainsLine("INFO|test.in.fo|Info with throwable"); - jul.assertContainsLine(ths); - } - - @Test - public void testWarnOutput() - { - jul.clear(); - - // Common Throwable (for test) - Throwable th = new Throwable("Message"); - - // Capture raw string form - StringWriter tout = new StringWriter(); - th.printStackTrace(new PrintWriter(tout)); - String ths = tout.toString(); - - // Tests - JavaUtilLog log = new JavaUtilLog("test.wa.rn"); - setJulLevel("test.wa.rn", Level.WARNING); - - log.warn("Simple warn"); - log.warn("Warn with {} parameter", 1); - log.warn("Warn with {} {} parameters", 2, "spiffy"); - log.warn("Warn with throwable", th); - log.warn(th); - - // jul.dump(); - - jul.assertContainsLine("WARNING|test.wa.rn|Simple warn"); - jul.assertContainsLine("WARNING|test.wa.rn|Warn with 1 parameter"); - jul.assertContainsLine("WARNING|test.wa.rn|Warn with 2 spiffy parameters"); - jul.assertContainsLine("WARNING|test.wa.rn|Warn with throwable"); - jul.assertContainsLine(ths); - } - - @Test - public void testFormattingWithNulls() - { - jul.clear(); - - JavaUtilLog log = new JavaUtilLog("test.nu.ll"); - setJulLevel("test.nu.ll", Level.INFO); - - log.info("Testing info(msg,null,null) - {} {}", "arg0", "arg1"); - log.info("Testing info(msg,null,null) - {}/{}", null, null); - log.info("Testing info(msg,null,null) > {}", null, null); - log.info("Testing info(msg,null,null)", null, null); - log.info(null, "Testing", "info(null,arg0,arg1)"); - log.info(null, null, null); - - //jul.dump(); - - jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) - null/null"); - jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) > null null"); - jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) null null"); - jul.assertContainsLine("INFO|test.nu.ll|null Testing info(null,arg0,arg1)"); - jul.assertContainsLine("INFO|test.nu.ll|null null null"); - } - - @Test - public void testIsDebugEnabled() - { - JavaUtilLog log = new JavaUtilLog("test.legacy"); - - setJulLevel("test.legacy", Level.ALL); - assertThat("log.level(all).isDebugEnabled", log.isDebugEnabled(), is(true)); - - setJulLevel("test.legacy", Level.FINEST); - assertThat("log.level(finest).isDebugEnabled", log.isDebugEnabled(), is(true)); - - setJulLevel("test.legacy", Level.FINER); - assertThat("log.level(finer).isDebugEnabled", log.isDebugEnabled(), is(true)); - - setJulLevel("test.legacy", Level.FINE); - assertThat("log.level(fine).isDebugEnabled", log.isDebugEnabled(), is(true)); - - setJulLevel("test.legacy", Level.INFO); - assertThat("log.level(info).isDebugEnabled", log.isDebugEnabled(), is(false)); - - setJulLevel("test.legacy", Level.WARNING); - assertThat("log.level(warn).isDebugEnabled", log.isDebugEnabled(), is(false)); - - log.setDebugEnabled(true); - assertThat("log.isDebugEnabled", log.isDebugEnabled(), is(true)); - - log.setDebugEnabled(false); - assertThat("log.isDebugEnabled", log.isDebugEnabled(), is(false)); - } - - private void setJulLevel(String name, Level lvl) - { - java.util.logging.Logger log = java.util.logging.Logger.getLogger(name); - log.setLevel(lvl); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java deleted file mode 100644 index ffc77ad0cff..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java +++ /dev/null @@ -1,141 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class LogTest -{ - // @checkstyle-disable-check : AvoidEscapedUnicodeCharactersCheck - private static Logger originalLogger; - private static Map originalLoggers; - - @BeforeAll - public static void rememberOriginalLogger() - { - originalLogger = Log.getLog(); - originalLoggers = new HashMap<>(Log.getLoggers()); - Log.getMutableLoggers().clear(); - } - - @AfterAll - public static void restoreOriginalLogger() - { - Log.setLog(originalLogger); - Log.getMutableLoggers().clear(); - Log.getMutableLoggers().putAll(originalLoggers); - } - - @Test - public void testDefaultLogging() - { - Logger log = Log.getLogger(LogTest.class); - log.info("Test default logging"); - } - - @Test - public void testNamedLogNamedStdErrLog() - { - Log.setLog(new StdErrLog()); - - assertNamedLogging(Red.class); - assertNamedLogging(Blue.class); - assertNamedLogging(Green.class); - } - - @Test - public void testNamedLogNamedJUL() - { - Log.setLog(new JavaUtilLog()); - - assertNamedLogging(Red.class); - assertNamedLogging(Blue.class); - assertNamedLogging(Green.class); - } - - @Test - public void testNamedLogNamedSlf4J() throws Exception - { - Log.setLog(new Slf4jLog()); - - assertNamedLogging(Red.class); - assertNamedLogging(Blue.class); - assertNamedLogging(Green.class); - } - - private void assertNamedLogging(Class clazz) - { - Logger lc = Log.getLogger(clazz); - assertEquals(lc.getName(), clazz.getName(), "Named logging (impl=" + Log.getLog().getClass().getName() + ")"); - } - - public static Stream packageCases() - { - return Stream.of( - // null entry - Arguments.of(null, ""), - // empty entry - Arguments.of("", ""), - // all whitespace entry - Arguments.of(" \t ", ""), - // bad / invalid characters - Arguments.of("org.eclipse.Foo.\u0000", "oe.Foo"), - Arguments.of("org.eclipse.\u20ac.Euro", "oe\u20ac.Euro"), - // bad package segments - Arguments.of(".foo", "foo"), - Arguments.of(".bar.Foo", "b.Foo"), - Arguments.of("org...bar..Foo", "ob.Foo"), - Arguments.of("org . . . bar . . Foo ", "ob.Foo"), - Arguments.of("org . . . bar . . Foo ", "ob.Foo"), - // long-ish classname - Arguments.of("org.eclipse.jetty.websocket.common.extensions.compress.DeflateFrameExtension", "oejwcec.DeflateFrameExtension"), - // internal class - Arguments.of("org.eclipse.jetty.foo.Bar$Internal", "oejf.Bar$Internal") - ); - } - - @ParameterizedTest - @MethodSource("packageCases") - public void testCondensePackageViaLogger(String input, String expected) - { - StdErrLog log = new StdErrLog(); - StdErrLog logger = (StdErrLog)log.newLogger(input); - assertThat("log[" + input + "] condenses to name", logger._abbrevname, is(expected)); - } - - @ParameterizedTest - @MethodSource("packageCases") - public void testCondensePackageDirect(String input, String expected) - { - assertThat("log[" + input + "] condenses to name", AbstractLogger.condensePackageString(input), is(expected)); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java deleted file mode 100644 index ffbdd878007..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java +++ /dev/null @@ -1,59 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import org.junit.jupiter.api.Test; - -public class NamedLogTest -{ - @Test - public void testNamedLogging() - { - Red red = new Red(); - Green green = new Green(); - Blue blue = new Blue(); - - StdErrCapture output = new StdErrCapture(); - - setLoggerOptions(Red.class, output); - setLoggerOptions(Green.class, output); - setLoggerOptions(Blue.class, output); - - red.generateLogs(); - green.generateLogs(); - blue.generateLogs(); - - output.assertContains(Red.class.getName()); - output.assertContains(Green.class.getName()); - output.assertContains(Blue.class.getName()); - } - - private void setLoggerOptions(Class clazz, StdErrCapture output) - { - Logger logger = Log.getLogger(clazz); - logger.setDebugEnabled(true); - - if (logger instanceof StdErrLog) - { - StdErrLog sel = (StdErrLog)logger; - sel.setPrintLongNames(true); - output.capture(sel); - } - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Red.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Red.java deleted file mode 100644 index 6bb0a4fc658..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Red.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -public class Red -{ - private static final Logger LOG = Log.getLogger(Red.class); - - public void generateLogs() - { - LOG.debug("My color is {}", Red.class.getSimpleName()); - LOG.info("I represent the emotion Love"); - LOG.warn("I can also mean Anger"); - LOG.ignore(new RuntimeException("Nom")); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jHelper.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jHelper.java deleted file mode 100644 index 1261961b9dd..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/Slf4jHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.File; -import java.io.FileFilter; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; - -import org.eclipse.jetty.toolchain.test.MavenTestingUtils; - -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -public final class Slf4jHelper -{ - public static ClassLoader createTestClassLoader(ClassLoader parentClassLoader) throws MalformedURLException - { - File testJarDir = MavenTestingUtils.getTargetFile("test-jars"); - assumeTrue(testJarDir.exists()); // trigger @Ignore if dir not there - - File[] jarfiles = testJarDir.listFiles(new FileFilter() - { - public boolean accept(File path) - { - if (!path.isFile()) - { - return false; - } - return path.getName().endsWith(".jar"); - } - }); - - assumeTrue(jarfiles.length > 0); // trigger @Ignore if no jar files. - - URL[] urls = new URL[jarfiles.length]; - for (int i = 0; i < jarfiles.length; i++) - { - urls[i] = jarfiles[i].toURI().toURL(); - // System.out.println("Adding test-jar => " + urls[i]); - } - - return new URLClassLoader(urls, parentClassLoader); - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java deleted file mode 100644 index 05d31b10fb2..00000000000 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java +++ /dev/null @@ -1,862 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; - -/** - * Tests for StdErrLog - */ -public class StdErrLogTest -{ - static - { - StdErrLog.setTagPad(0); - } - - @BeforeEach - public void before() - { - Thread.currentThread().setName("tname"); - } - - @Test - public void testStdErrLogFormat() - { - StdErrLog log = new StdErrLog(LogTest.class.getName(), new Properties()); - StdErrCapture output = new StdErrCapture(log); - - log.info("testing:{},{}", "test", "format1"); - log.info("testing:{}", "test", "format2"); - log.info("testing", "test", "format3"); - log.info("testing:{},{}", "test", null); - log.info("testing {} {}", null, null); - log.info("testing:{}", null, null); - log.info("testing", null, null); - - System.err.println(output); - output.assertContains("INFO:oejul.LogTest:tname: testing:test,format1"); - output.assertContains("INFO:oejul.LogTest:tname: testing:test format2"); - output.assertContains("INFO:oejul.LogTest:tname: testing test format3"); - output.assertContains("INFO:oejul.LogTest:tname: testing:test,"); - output.assertContains("INFO:oejul.LogTest:tname: testing"); - output.assertContains("INFO:oejul.LogTest:tname: testing:"); - output.assertContains("INFO:oejul.LogTest:tname: testing"); - } - - @Test - public void testStdErrLogDebug() - { - StdErrLog log = new StdErrLog("xxx", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - log.setLevel(StdErrLog.LEVEL_DEBUG); - log.debug("testing {} {}", "test", "debug"); - log.info("testing {} {}", "test", "info"); - log.warn("testing {} {}", "test", "warn"); - log.setLevel(StdErrLog.LEVEL_INFO); - log.debug("YOU SHOULD NOT SEE THIS!", null, null); - - // Test for backward compat with old (now deprecated) method - Logger before = log.getLogger("before"); - log.setDebugEnabled(true); - Logger after = log.getLogger("after"); - before.debug("testing {} {}", "test", "debug-before"); - log.debug("testing {} {}", "test", "debug-deprecated"); - after.debug("testing {} {}", "test", "debug-after"); - - log.setDebugEnabled(false); - before.debug("testing {} {}", "test", "debug-before-false"); - log.debug("testing {} {}", "test", "debug-deprecated-false"); - after.debug("testing {} {}", "test", "debug-after-false"); - - output.assertContains("DBUG:xxx:tname: testing test debug"); - output.assertContains("INFO:xxx:tname: testing test info"); - output.assertContains("WARN:xxx:tname: testing test warn"); - output.assertNotContains("YOU SHOULD NOT SEE THIS!"); - output.assertContains("DBUG:x.before:tname: testing test debug-before"); - output.assertContains("DBUG:xxx:tname: testing test debug-deprecated"); - output.assertContains("DBUG:x.after:tname: testing test debug-after"); - output.assertNotContains("DBUG:x.before:tname: testing test debug-before-false"); - output.assertNotContains("DBUG:xxx:tname: testing test debug-deprecated-false"); - output.assertNotContains("DBUG:x.after:tname: testing test debug-after-false"); - } - - @Test - public void testStdErrLogName() - { - StdErrLog log = new StdErrLog("testX", new Properties()); - log.setPrintLongNames(true); - StdErrCapture output = new StdErrCapture(log); - - assertThat("Log.name", log.getName(), is("testX")); - Logger next = log.getLogger("next"); - assertThat("Log.name(child)", next.getName(), is("testX.next")); - next.info("testing {} {}", "next", "info"); - - output.assertContains(":testX.next:tname: testing next info"); - } - - @Test - public void testStdErrMsgThrowable() - { - // The test Throwable - Throwable th = new Throwable("Message"); - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.warn("ex", th); // Behavior here is being tested - output.assertContains(asString(th)); - } - - @SuppressWarnings("ConstantConditions") - @Test - public void testStdErrMsgThrowableNull() - { - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - Throwable th = null; - log.warn("ex", th); - output.assertContains("testX"); - output.assertNotContains("null"); - } - - @Test - public void testStdErrThrowable() - { - // The test Throwable - Throwable th = new Throwable("Message"); - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.warn(th); - output.assertContains(asString(th)); - } - - @Test - public void testStdErrThrowableNull() - { - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - Throwable th = null; - log.warn(th); // Behavior here is being tested - output.assertContains("testX"); - output.assertNotContains("null"); - } - - @Test - public void testStdErrFormatArgsThrowable() - { - // The test throwable - Throwable th = new Throwable("Reasons Explained"); - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.warn("Ex {}", "Reasons", th); - output.assertContains("Reasons"); - output.assertContains(asString(th)); - } - - @SuppressWarnings("ConstantConditions") - @Test - public void testStdErrFormatArgsThrowableNull() - { - // The test throwable - Throwable th = null; - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.warn("Ex {}", "Reasons", th); - output.assertContains("Reasons"); - output.assertNotContains("null"); - } - - @Test - public void testStdErrMsgThrowableWithControlChars() - { - // The test throwable, using "\b" (backspace) character - Throwable th = new Throwable("Message with \b backspace"); - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.warn("ex", th); - output.assertNotContains("Message with \b backspace"); - output.assertContains("Message with ? backspace"); - } - - @Test - public void testStdErrMsgStringThrowableWithControlChars() - { - // The test throwable, using "\b" (backspace) character - Throwable th = new Throwable("Message with \b backspace"); - - // Initialize Logger - StdErrLog log = new StdErrLog("testX", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - // Test behavior - log.info(th.toString()); - output.assertNotContains("Message with \b backspace"); - output.assertContains("Message with ? backspace"); - } - - private String asString(Throwable cause) - { - StringWriter tout = new StringWriter(); - cause.printStackTrace(new PrintWriter(tout)); - return tout.toString(); - } - - /** - * Test to make sure that using a Null parameter on parameterized messages does not result in a NPE - */ - @Test - public void testParameterizedMessageNullValues() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - log.setLevel(StdErrLog.LEVEL_DEBUG); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - log.info("Testing info(msg,null,null) - {} {}", "arg0", "arg1"); - log.info("Testing info(msg,null,null) - {} {}", null, null); - log.info("Testing info(msg,null,null) - {}", null, null); - log.info("Testing info(msg,null,null)", null, null); - log.info(null, "Testing", "info(null,arg0,arg1)"); - log.info(null, null, null); - - log.debug("Testing debug(msg,null,null) - {} {}", "arg0", "arg1"); - log.debug("Testing debug(msg,null,null) - {} {}", null, null); - log.debug("Testing debug(msg,null,null) - {}", null, null); - log.debug("Testing debug(msg,null,null)", null, null); - log.debug(null, "Testing", "debug(null,arg0,arg1)"); - log.debug(null, null, null); - - log.debug("Testing debug(msg,null)"); - log.debug(null, new Throwable("Testing debug(null,thrw)").fillInStackTrace()); - - log.warn("Testing warn(msg,null,null) - {} {}", "arg0", "arg1"); - log.warn("Testing warn(msg,null,null) - {} {}", null, null); - log.warn("Testing warn(msg,null,null) - {}", null, null); - log.warn("Testing warn(msg,null,null)", null, null); - log.warn(null, "Testing", "warn(msg,arg0,arg1)"); - log.warn(null, null, null); - - log.warn("Testing warn(msg,null)"); - log.warn(null, new Throwable("Testing warn(msg,thrw)").fillInStackTrace()); - } - } - - @Test - public void testGetLoggingLevelDefault() - { - Properties props = new Properties(); - - // Default Levels - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, null), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, ""), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty"), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, StdErrLogTest.class.getName()), "Default Logging Level"); - } - - @Test - public void testGetLoggingLevelBad() - { - Properties props = new Properties(); - props.setProperty("log.LEVEL", "WARN"); - props.setProperty("org.eclipse.jetty.bad.LEVEL", "EXPECTED_BAD_LEVEL"); - - // Default Level (because of bad level value) - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.bad"), "Bad Logging Level"); - } - - @Test - public void testGetLoggingLevelLowercase() - { - Properties props = new Properties(); - props.setProperty("log.LEVEL", "warn"); - props.setProperty("org.eclipse.jetty.util.LEVEL", "info"); - - // Default Level - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty"), "Lowercase Level"); - // Specific Level - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util"), "Lowercase Level"); - } - - @Test - public void testGetLoggingLevelRoot() - { - Properties props = new Properties(); - props.setProperty("log.LEVEL", "DEBUG"); - - // Default Levels - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, null), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, ""), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty"), "Default Logging Level"); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, StdErrLogTest.class.getName()), "Default Logging Level"); - } - - @Test - public void testGetLoggingLevelFQCN() - { - String name = StdErrLogTest.class.getName(); - Properties props = new Properties(); - props.setProperty(name + ".LEVEL", "ALL"); - - // Default Levels - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, null)); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "")); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty")); - - // Specified Level - assertEquals(StdErrLog.LEVEL_ALL, StdErrLog.getLoggingLevel(props, name)); - } - - @Test - public void testGetLoggingLevelUtilLevel() - { - Properties props = new Properties(); - props.setProperty("org.eclipse.jetty.util.LEVEL", "DEBUG"); - - // Default Levels - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, null)); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "")); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty")); - assertEquals(StdErrLog.LEVEL_INFO, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.server.BogusObject")); - - // Configured Level - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, StdErrLogTest.class.getName())); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util.Bogus")); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util")); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util.resource.PathResource")); - } - - @Test - public void testGetLoggingLevelMixedLevels() - { - Properties props = new Properties(); - props.setProperty("log.LEVEL", "DEBUG"); - props.setProperty("org.eclipse.jetty.util.LEVEL", "WARN"); - props.setProperty("org.eclipse.jetty.util.ConcurrentHashMap.LEVEL", "ALL"); - - // Default Levels - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, null)); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "")); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty")); - assertEquals(StdErrLog.LEVEL_DEBUG, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.server.ServerObject")); - - // Configured Level - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, StdErrLogTest.class.getName())); - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util.MagicUtil")); - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util")); - assertEquals(StdErrLog.LEVEL_WARN, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util.resource.PathResource")); - assertEquals(StdErrLog.LEVEL_ALL, StdErrLog.getLoggingLevel(props, "org.eclipse.jetty.util.ConcurrentHashMap")); - } - - /** - * Tests StdErrLog.warn() methods with level filtering. - *

- * Should always see WARN level messages, regardless of set level. - */ - @Test - public void testWarnFiltering() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - StdErrCapture output = new StdErrCapture(log); - - // Start with default level - log.warn("See Me"); - - // Set to debug level - log.setLevel(StdErrLog.LEVEL_DEBUG); - log.warn("Hear Me"); - - // Set to warn level - log.setLevel(StdErrLog.LEVEL_WARN); - log.warn("Cheer Me"); - - log.warn("", new Throwable("out of focus")); - log.warn(new Throwable("scene lost")); - - // Validate Output - // System.err.print(output); - output.assertContains("See Me"); - output.assertContains("Hear Me"); - output.assertContains("Cheer Me"); - - // Validate Stack Traces - output.assertContains(".StdErrLogTest:tname: "); - output.assertContains("java.lang.Throwable: out of focus"); - output.assertContains("java.lang.Throwable: scene lost"); - } - } - - /** - * Tests StdErrLog.info() methods with level filtering. - *

- * Should only see INFO level messages when level is set to {@link StdErrLog#LEVEL_INFO} and below. - */ - @Test - public void testInfoFiltering() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - StdErrCapture output = new StdErrCapture(log); - - // Normal/Default behavior - log.info("I will not buy"); - - // Level Debug - log.setLevel(StdErrLog.LEVEL_DEBUG); - log.info("this record"); - - // Level All - log.setLevel(StdErrLog.LEVEL_ALL); - log.info("it is scratched."); - - log.info("", new Throwable("out of focus")); - log.info(new Throwable("scene lost")); - - // Level Warn - log.setLevel(StdErrLog.LEVEL_WARN); - log.info("sorry?"); - log.info("", new Throwable("on editing room floor")); - - // Validate Output - output.assertContains("I will not buy"); - output.assertContains("this record"); - output.assertContains("it is scratched."); - output.assertNotContains("sorry?"); - - // Validate Stack Traces - output.assertNotContains(""); - output.assertNotContains("on editing room floor"); - - output.assertContains(".StdErrLogTest:tname: "); - output.assertContains("java.lang.Throwable: out of focus"); - output.assertContains("java.lang.Throwable: scene lost"); - } - } - - /** - * Tests {@link StdErrLog#LEVEL_OFF} filtering. - */ - @Test - public void testOffFiltering() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - log.setLevel(StdErrLog.LEVEL_OFF); - - StdErrCapture output = new StdErrCapture(log); - - // Various logging events - log.debug("Squelch"); - log.debug("Squelch", new RuntimeException("Squelch")); - log.info("Squelch"); - log.info("Squelch", new IllegalStateException("Squelch")); - log.warn("Squelch"); - log.warn("Squelch", new Exception("Squelch")); - log.ignore(new Throwable("Squelch")); - - // Validate Output - output.assertNotContains("Squelch"); - } - } - - /** - * Tests StdErrLog.debug() methods with level filtering. - *

- * Should only see DEBUG level messages when level is set to {@link StdErrLog#LEVEL_DEBUG} and below. - */ - @Test - public void testDebugFiltering() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - StdErrCapture output = new StdErrCapture(log); - - // Normal/Default behavior - log.debug("Tobacconist"); - log.debug("", new Throwable("on editing room floor")); - - // Level Debug - log.setLevel(StdErrLog.LEVEL_DEBUG); - log.debug("my hovercraft is"); - - log.debug("", new Throwable("out of focus")); - log.debug(new Throwable("scene lost")); - - // Level All - log.setLevel(StdErrLog.LEVEL_ALL); - log.debug("full of eels."); - - // Level Warn - log.setLevel(StdErrLog.LEVEL_WARN); - log.debug("what?"); - - // Validate Output - // System.err.print(output); - output.assertNotContains("Tobacconist"); - output.assertContains("my hovercraft is"); - output.assertContains("full of eels."); - output.assertNotContains("what?"); - - // Validate Stack Traces - output.assertNotContains(""); - output.assertNotContains("on editing room floor"); - - output.assertContains(".StdErrLogTest:tname: "); - output.assertContains("java.lang.Throwable: out of focus"); - output.assertContains("java.lang.Throwable: scene lost"); - } - } - - /** - * Tests StdErrLog with {@link Logger#ignore(Throwable)} use. - *

- * Should only see IGNORED level messages when level is set to {@link StdErrLog#LEVEL_ALL}. - */ - @Test - public void testIgnores() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - StdErrCapture output = new StdErrCapture(log); - - // Normal/Default behavior - log.ignore(new Throwable("IGNORE ME")); - - // Show Ignored - log.setLevel(StdErrLog.LEVEL_ALL); - log.ignore(new Throwable("Don't ignore me")); - - // Set to Debug level - log.setLevel(StdErrLog.LEVEL_DEBUG); - log.ignore(new Throwable("Debug me")); - - // Validate Output - // System.err.print(output); - output.assertNotContains("IGNORE ME"); - output.assertContains("Don't ignore me"); - output.assertNotContains("Debug me"); - } - } - - @Test - public void testIsDebugEnabled() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - log.setLevel(StdErrLog.LEVEL_ALL); - assertThat("log.level(all).isDebugEnabled", log.isDebugEnabled(), is(true)); - - log.setLevel(StdErrLog.LEVEL_DEBUG); - assertThat("log.level(debug).isDebugEnabled", log.isDebugEnabled(), is(true)); - - log.setLevel(StdErrLog.LEVEL_INFO); - assertThat("log.level(info).isDebugEnabled", log.isDebugEnabled(), is(false)); - - log.setLevel(StdErrLog.LEVEL_WARN); - assertThat("log.level(warn).isDebugEnabled", log.isDebugEnabled(), is(false)); - - log.setLevel(StdErrLog.LEVEL_OFF); - assertThat("log.level(off).isDebugEnabled", log.isDebugEnabled(), is(false)); - } - } - - @Test - public void testSetGetLevel() - { - StdErrLog log = new StdErrLog(StdErrLogTest.class.getName(), new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - log.setLevel(StdErrLog.LEVEL_ALL); - assertThat("log.level(all).getLevel()", log.getLevel(), is(StdErrLog.LEVEL_ALL)); - - log.setLevel(StdErrLog.LEVEL_DEBUG); - assertThat("log.level(debug).getLevel()", log.getLevel(), is(StdErrLog.LEVEL_DEBUG)); - - log.setLevel(StdErrLog.LEVEL_INFO); - assertThat("log.level(info).getLevel()", log.getLevel(), is(StdErrLog.LEVEL_INFO)); - - log.setLevel(StdErrLog.LEVEL_WARN); - assertThat("log.level(warn).getLevel()", log.getLevel(), is(StdErrLog.LEVEL_WARN)); - - log.setLevel(StdErrLog.LEVEL_OFF); - assertThat("log.level(off).getLevel()", log.getLevel(), is(StdErrLog.LEVEL_OFF)); - } - } - - @Test - public void testGetChildLoggerSimple() - { - String baseName = "jetty"; - StdErrLog log = new StdErrLog(baseName, new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - assertThat("Logger.name", log.getName(), is("jetty")); - - Logger log2 = log.getLogger("child"); - assertThat("Logger.child.name", log2.getName(), is("jetty.child")); - } - } - - @Test - public void testGetChildLoggerDeep() - { - String baseName = "jetty"; - StdErrLog log = new StdErrLog(baseName, new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - assertThat("Logger.name", log.getName(), is("jetty")); - - Logger log2 = log.getLogger("child.of.the.sixties"); - assertThat("Logger.child.name", log2.getName(), is("jetty.child.of.the.sixties")); - } - } - - @Test - public void testGetChildLoggerNull() - { - String baseName = "jetty"; - StdErrLog log = new StdErrLog(baseName, new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - assertThat("Logger.name", log.getName(), is("jetty")); - - // Pass null as child reference, should return parent logger - Logger log2 = log.getLogger((String)null); - assertThat("Logger.child.name", log2.getName(), is("jetty")); - assertSame(log2, log, "Should have returned same logger"); - } - } - - @Test - public void testGetChildLoggerEmptyName() - { - String baseName = "jetty"; - StdErrLog log = new StdErrLog(baseName, new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - assertThat("Logger.name", log.getName(), is("jetty")); - - // Pass empty name as child reference, should return parent logger - Logger log2 = log.getLogger(""); - assertThat("Logger.child.name", log2.getName(), is("jetty")); - assertSame(log2, log, "Should have returned same logger"); - } - } - - @Test - public void testGetChildLoggerEmptyNameSpaces() - { - String baseName = "jetty"; - StdErrLog log = new StdErrLog(baseName, new Properties()); - try (StacklessLogging ignored = new StacklessLogging(log)) - { - assertThat("Logger.name", log.getName(), is("jetty")); - - // Pass empty name as child reference, should return parent logger - Logger log2 = log.getLogger(" "); - assertThat("Logger.child.name", log2.getName(), is("jetty")); - assertSame(log2, log, "Should have returned same logger"); - } - } - - @Test - public void testGetChildLoggerNullParent() - { - AbstractLogger log = new StdErrLog(null, new Properties()); - - assertThat("Logger.name", log.getName(), is("")); - - Logger log2 = log.getLogger("jetty"); - assertThat("Logger.child.name", log2.getName(), is("jetty")); - assertNotSame(log2, log, "Should have returned same logger"); - } - - @Test - public void testToString() - { - StdErrLog log = new StdErrLog("jetty", new Properties()); - - log.setLevel(StdErrLog.LEVEL_ALL); - assertThat("Logger.toString", log.toString(), is("StdErrLog:jetty:LEVEL=ALL")); - - log.setLevel(StdErrLog.LEVEL_DEBUG); - assertThat("Logger.toString", log.toString(), is("StdErrLog:jetty:LEVEL=DEBUG")); - - log.setLevel(StdErrLog.LEVEL_INFO); - assertThat("Logger.toString", log.toString(), is("StdErrLog:jetty:LEVEL=INFO")); - - log.setLevel(StdErrLog.LEVEL_WARN); - assertThat("Logger.toString", log.toString(), is("StdErrLog:jetty:LEVEL=WARN")); - - log.setLevel(99); // intentionally bogus level - assertThat("Logger.toString", log.toString(), is("StdErrLog:jetty:LEVEL=?")); - } - - @Test - public void testPrintSource() - { - Properties props = new Properties(); - props.put("test.SOURCE", "true"); - StdErrLog log = new StdErrLog("test", props); - log.setLevel(StdErrLog.LEVEL_DEBUG); - - ByteArrayOutputStream test = new ByteArrayOutputStream(); - PrintStream err = new PrintStream(test); - log.setStdErrStream(err); - - log.debug("Show me the source!"); - - String output = new String(test.toByteArray(), StandardCharsets.UTF_8); - // System.err.print(output); - - assertThat(output, containsString(".StdErrLogTest#testPrintSource(StdErrLogTest.java:")); - - props.put("test.SOURCE", "false"); - } - - @Test - public void testConfiguredAndSetDebugEnabled() - { - Properties props = new Properties(); - props.setProperty("org.eclipse.jetty.util.LEVEL", "WARN"); - props.setProperty("org.eclipse.jetty.io.LEVEL", "WARN"); - - StdErrLog root = new StdErrLog("", props); - assertLevel(root, StdErrLog.LEVEL_INFO); // default - - StdErrLog log = (StdErrLog)root.getLogger(StdErrLogTest.class.getName()); - assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(false)); - assertLevel(log, StdErrLog.LEVEL_WARN); // as configured - - // Boot stomp it all to debug - root.setDebugEnabled(true); - assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(true)); - assertLevel(log, StdErrLog.LEVEL_DEBUG); // as stomped - - // Restore configured - root.setDebugEnabled(false); - assertThat("Log.isDebugEnabled()", log.isDebugEnabled(), is(false)); - assertLevel(log, StdErrLog.LEVEL_WARN); // as configured - } - - @Test - public void testSuppressed() - { - StdErrLog log = new StdErrLog("xxx", new Properties()); - StdErrCapture output = new StdErrCapture(log); - - Exception inner = new Exception("inner"); - inner.addSuppressed(new IllegalStateException() - { - { - addSuppressed(new Exception("branch0")); - } - }); - IOException outer = new IOException("outer", inner); - - outer.addSuppressed(new IllegalStateException() - { - { - addSuppressed(new Exception("branch1")); - } - }); - outer.addSuppressed(new IllegalArgumentException() - { - { - addSuppressed(new Exception("branch2")); - } - }); - - log.warn("problem", outer); - - output.assertContains("\t|\t|java.lang.Exception: branch2"); - output.assertContains("\t|\t|java.lang.Exception: branch1"); - output.assertContains("\t|\t|java.lang.Exception: branch0"); - } - - private void assertLevel(StdErrLog log, int expectedLevel) - { - assertThat("Log[" + log.getName() + "].level", levelToString(log.getLevel()), is(levelToString(expectedLevel))); - } - - private String levelToString(int level) - { - switch (level) - { - case StdErrLog.LEVEL_ALL: - return "ALL"; - case StdErrLog.LEVEL_DEBUG: - return "DEBUG"; - case StdErrLog.LEVEL_INFO: - return "INFO"; - case StdErrLog.LEVEL_WARN: - return "WARN"; - default: - return Integer.toString(level); - } - } -} diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java index 680601b7b28..15d8228f427 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java @@ -28,8 +28,8 @@ import java.util.stream.Stream; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/EatWhatYouKillTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/EatWhatYouKillTest.java index 77c5fe3f36f..3db735633ac 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/EatWhatYouKillTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/EatWhatYouKillTest.java @@ -24,7 +24,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.thread.strategy.EatWhatYouKill; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index 488cf728e0c..521f31f05e7 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -23,9 +23,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool; import org.junit.jupiter.api.Test; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java index 327a80b9573..dee33a0351d 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Stream; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SweeperTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SweeperTest.java index 0e48f207a20..7dda9d36263 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SweeperTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SweeperTest.java @@ -21,7 +21,7 @@ package org.eclipse.jetty.util.thread; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-util/src/test/resources/jetty-logging.properties b/jetty-util/src/test/resources/jetty-logging.properties index 7367559fac9..c82f81c0424 100644 --- a/jetty-util/src/test/resources/jetty-logging.properties +++ b/jetty-util/src/test/resources/jetty-logging.properties @@ -1,5 +1,5 @@ # Setup default logging implementation for during testing -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.util.LEVEL=DEBUG #org.eclipse.jetty.util.PathWatcher.LEVEL=DEBUG #org.eclipse.jetty.util.thread.QueuedThreadPool.LEVEL=DEBUG diff --git a/jetty-webapp/src/main/java/module-info.java b/jetty-webapp/src/main/java/module-info.java index e31775ebe26..fc1fd191d5a 100644 --- a/jetty-webapp/src/main/java/module-info.java +++ b/jetty-webapp/src/main/java/module-info.java @@ -25,6 +25,7 @@ module org.eclipse.jetty.webapp requires transitive java.instrument; requires transitive org.eclipse.jetty.servlet; requires transitive org.eclipse.jetty.xml; + requires org.slf4j; uses Configuration; diff --git a/jetty-webapp/src/test/resources/jetty-logging.properties b/jetty-webapp/src/test/resources/jetty-logging.properties index 9e7b0a45e6d..3d9406bcb9b 100644 --- a/jetty-webapp/src/test/resources/jetty-logging.properties +++ b/jetty-webapp/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.webapp.LEVEL=DEBUG # org.eclipse.jetty.util.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-core/src/main/java/module-info.java b/jetty-websocket/websocket-core/src/main/java/module-info.java index 7c8772d9563..c2fa64dda77 100644 --- a/jetty-websocket/websocket-core/src/main/java/module-info.java +++ b/jetty-websocket/websocket-core/src/main/java/module-info.java @@ -33,6 +33,7 @@ module org.eclipse.jetty.websocket.core requires jetty.servlet.api; requires transitive org.eclipse.jetty.client; requires transitive org.eclipse.jetty.server; + requires org.slf4j; // Only required if using XmlHttpClientProvider. requires static org.eclipse.jetty.xml; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java index ed607ea7cb1..6fe3e60b6c5 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadCloseStatusCodesTest.java @@ -23,8 +23,8 @@ import java.util.stream.Stream; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Parser; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java index 261d48281ef..a0dfcd2167a 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserBadOpCodesTest.java @@ -23,8 +23,8 @@ import java.util.stream.Stream; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Parser; import org.junit.jupiter.params.ParameterizedTest; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java index 2ce09923b9d..de95ce6a109 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserReservedBitTest.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.exception.ProtocolException; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.Parser; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java index 2ede334dacd..4a47c433aaf 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java @@ -27,6 +27,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -37,7 +38,6 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java index 78fe389f140..5f9e5482426 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java @@ -33,10 +33,10 @@ import org.eclipse.jetty.client.HttpRequest; import org.eclipse.jetty.client.HttpResponse; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.UpgradeListener; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java index 3c10794880e..4d3b32a0600 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java @@ -23,10 +23,10 @@ import java.util.concurrent.Exchanger; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.internal.Parser; import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; import org.junit.jupiter.api.AfterEach; diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java index 3a6f381614b..ea7a478f93f 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -37,7 +38,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Configuration; import org.eclipse.jetty.websocket.core.CoreSession; diff --git a/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties index c38077cdd6f..9034a88c25a 100644 --- a/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.io.LEVEL=DEBUG # org.eclipse.jetty.websocket.core.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-javax-client/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-javax-client/src/test/resources/jetty-logging.properties index 536192ce715..a67f4bd5675 100644 --- a/jetty-websocket/websocket-javax-client/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-javax-client/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=INFO # org.eclipse.jetty.websocket.LEVEL=DEBUG # org.eclipse.jetty.server.AbstractConnector.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-javax-common/src/main/java/module-info.java b/jetty-websocket/websocket-javax-common/src/main/java/module-info.java index 89d937226be..08b85dda862 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/module-info.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/module-info.java @@ -28,4 +28,5 @@ module org.eclipse.jetty.websocket.javax.common requires transitive org.eclipse.jetty.io; requires transitive org.eclipse.jetty.websocket.core; requires transitive org.eclipse.jetty.websocket.util; + requires org.slf4j; } diff --git a/jetty-websocket/websocket-javax-common/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-javax-common/src/test/resources/jetty-logging.properties index ef7003a8baa..274e97067c1 100644 --- a/jetty-websocket/websocket-javax-common/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-javax-common/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.util.log.stderr.LONG=true # org.eclipse.jetty.server.AbstractConnector.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-javax-server/src/main/java/module-info.java b/jetty-websocket/websocket-javax-server/src/main/java/module-info.java index 5f22863fa27..2fa8b121f48 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/module-info.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/module-info.java @@ -31,6 +31,7 @@ module org.eclipse.jetty.websocket.javax.server requires transitive org.eclipse.jetty.webapp; requires transitive org.eclipse.jetty.websocket.javax.client; requires org.eclipse.jetty.websocket.servlet; + requires org.slf4j; provides ServletContainerInitializer with JavaxWebSocketServletContainerInitializer; provides ServerEndpointConfig.Configurator with ContainerDefaultConfigurator; diff --git a/jetty-websocket/websocket-javax-server/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-javax-server/src/test/resources/jetty-logging.properties index cfafdb369a4..67577df4375 100644 --- a/jetty-websocket/websocket-javax-server/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-javax-server/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.websocket.LEVEL=DEBUG # org.eclipse.jetty.websocket.LEVEL=INFO diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/misbehaving/MisbehavingClassTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/misbehaving/MisbehavingClassTest.java index 7182540c054..d59fa0d0648 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/misbehaving/MisbehavingClassTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/misbehaving/MisbehavingClassTest.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; import javax.websocket.ContainerProvider; import javax.websocket.WebSocketContainer; -import org.eclipse.jetty.util.log.StacklessLogging; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession; import org.eclipse.jetty.websocket.javax.tests.CoreServer; import org.junit.jupiter.api.AfterEach; diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java index 9dc378e99ea..4948dc66515 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java @@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit; import com.acme.websocket.IdleTimeoutContextListener; import com.acme.websocket.IdleTimeoutOnOpenEndpoint; import com.acme.websocket.IdleTimeoutOnOpenSocket; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.Frame; diff --git a/jetty-websocket/websocket-javax-tests/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-javax-tests/src/test/resources/jetty-logging.properties index d60b503ca8b..7485b6d2a83 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-javax-tests/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.util.log.stderr.LONG=true # org.eclipse.jetty.server.AbstractConnector.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java b/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java index 5285a8ab1bc..3ce30e0ec89 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/module-info.java @@ -23,4 +23,5 @@ module org.eclipse.jetty.websocket.jetty.client requires transitive org.eclipse.jetty.client; requires org.eclipse.jetty.websocket.core; requires transitive org.eclipse.jetty.websocket.jetty.common; + requires org.slf4j; } diff --git a/jetty-websocket/websocket-jetty-client/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-jetty-client/src/test/resources/jetty-logging.properties index b88f6f45f02..8816a29ffa1 100644 --- a/jetty-websocket/websocket-jetty-client/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-jetty-client/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.io.LEVEL=INFO # org.eclipse.jetty.client.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/module-info.java b/jetty-websocket/websocket-jetty-common/src/main/java/module-info.java index b8ecb8308b0..18f6fe37564 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/module-info.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/module-info.java @@ -26,6 +26,7 @@ module org.eclipse.jetty.websocket.jetty.common requires transitive org.eclipse.jetty.websocket.core; requires transitive org.eclipse.jetty.websocket.util; requires transitive org.eclipse.jetty.websocket.jetty.api; + requires org.slf4j; provides ExtensionConfig.Parser with ExtensionConfigParser; } diff --git a/jetty-websocket/websocket-jetty-common/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-jetty-common/src/test/resources/jetty-logging.properties index 07faa86dbce..376b9b6babb 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-jetty-common/src/test/resources/jetty-logging.properties @@ -1 +1 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog \ No newline at end of file +# Jetty Logging using jetty-slf4j-impl diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/module-info.java b/jetty-websocket/websocket-jetty-server/src/main/java/module-info.java index 74b6da4183c..62969c6d386 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/module-info.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/module-info.java @@ -31,6 +31,7 @@ module org.eclipse.jetty.websocket.jetty.server requires transitive org.eclipse.jetty.webapp; requires transitive org.eclipse.jetty.websocket.jetty.common; requires transitive org.eclipse.jetty.websocket.servlet; + requires org.slf4j; // Only required if using JMX. requires static org.eclipse.jetty.jmx; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ErrorCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ErrorCloseTest.java index 7f0ee5e8f37..0e077b8d7ff 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ErrorCloseTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ErrorCloseTest.java @@ -28,10 +28,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.servlet.DispatcherType; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketSessionListener; import org.eclipse.jetty.websocket.api.annotations.WebSocket; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketNegotiationTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketNegotiationTest.java index 622307f8374..2c7efe059b0 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketNegotiationTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketNegotiationTest.java @@ -23,11 +23,11 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java index 0de62611fe9..46353096544 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java @@ -43,6 +43,7 @@ import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory; import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.ClientConnector; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -53,7 +54,6 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.websocket.api.Session; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameAnnotationTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameAnnotationTest.java index 0943a335e6e..c79c67582f5 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameAnnotationTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameAnnotationTest.java @@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; @@ -31,7 +32,6 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.Frame; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java index 0085c468a65..dc2107f2727 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java @@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; @@ -31,7 +32,6 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.Frame; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java index 5733c87d828..1c2804d59f4 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java @@ -25,6 +25,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; @@ -32,7 +33,6 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketPartialListener; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java index 8870a9868d2..3277da8b00c 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java @@ -23,13 +23,13 @@ import java.nio.channels.ClosedChannelException; import java.time.Duration; import java.util.concurrent.Future; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.util.WSURI; diff --git a/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties index 41e1bef3cd0..f53242c83bf 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-jetty-tests/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl # org.eclipse.jetty.LEVEL=DEBUG # org.eclipse.jetty.websocket.LEVEL=DEBUG # org.eclipse.jetty.websocket.test.LEVEL=DEBUG diff --git a/jetty-websocket/websocket-servlet/src/main/java/module-info.java b/jetty-websocket/websocket-servlet/src/main/java/module-info.java index 7c70a9feeff..93715204b9d 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/module-info.java +++ b/jetty-websocket/websocket-servlet/src/main/java/module-info.java @@ -22,4 +22,5 @@ module org.eclipse.jetty.websocket.servlet requires transitive org.eclipse.jetty.servlet; requires transitive org.eclipse.jetty.websocket.core; + requires org.slf4j; } diff --git a/jetty-websocket/websocket-util/src/main/java/module-info.java b/jetty-websocket/websocket-util/src/main/java/module-info.java index 06dadf1a9a5..183e1fd2715 100644 --- a/jetty-websocket/websocket-util/src/main/java/module-info.java +++ b/jetty-websocket/websocket-util/src/main/java/module-info.java @@ -21,5 +21,6 @@ module org.eclipse.jetty.websocket.util exports org.eclipse.jetty.websocket.util; exports org.eclipse.jetty.websocket.util.messages; + requires org.slf4j; requires transitive org.eclipse.jetty.websocket.core; } diff --git a/jetty-websocket/websocket-util/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-util/src/test/resources/jetty-logging.properties index 07faa86dbce..376b9b6babb 100644 --- a/jetty-websocket/websocket-util/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-util/src/test/resources/jetty-logging.properties @@ -1 +1 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog \ No newline at end of file +# Jetty Logging using jetty-slf4j-impl diff --git a/jetty-xml/src/main/java/module-info.java b/jetty-xml/src/main/java/module-info.java index 4a6c797c183..6c26b215b96 100644 --- a/jetty-xml/src/main/java/module-info.java +++ b/jetty-xml/src/main/java/module-info.java @@ -24,6 +24,7 @@ module org.eclipse.jetty.xml requires transitive java.xml; requires transitive org.eclipse.jetty.util; + requires org.slf4j; uses ConfigurationProcessorFactory; } diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index 8c5219be3b9..cbf7f2ab28d 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -36,22 +36,25 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import org.eclipse.jetty.logging.JettyLogger; +import org.eclipse.jetty.logging.StdErrAppender; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.annotation.Name; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.event.Level; import org.xml.sax.SAXException; import static java.nio.charset.StandardCharsets.UTF_8; @@ -1389,23 +1392,20 @@ public class XmlConfigurationTest " \n" + ""); - Logger logger = Log.getLogger(XmlConfiguration.class); - assertTrue(logger instanceof StdErrLog); - StdErrLog stdErrLog = (StdErrLog)logger; - ByteArrayOutputStream logBytes = new ByteArrayOutputStream(); - stdErrLog.setStdErrStream(new PrintStream(logBytes)); + ByteArrayOutputStream logBytes = captureLoggingBytes(() -> + { + Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar); + Object obj = idMap.get("bar"); + assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); + BarNamed bar = (BarNamed)obj; + assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); + }); - Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar); - Object obj = idMap.get("bar"); - assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); - BarNamed bar = (BarNamed)obj; - assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); - - List warnLogs = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) + List warnings = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) .filter(line -> line.contains(":WARN")) .collect(Collectors.toList()); - assertThat("WARN logs size", warnLogs.size(), is(0)); + assertThat("WARN logs size", warnings.size(), is(0)); } @Test @@ -1422,23 +1422,20 @@ public class XmlConfigurationTest " \n" + // no name specified ""); - Logger logger = Log.getLogger(XmlConfiguration.class); - assertTrue(logger instanceof StdErrLog); - StdErrLog stdErrLog = (StdErrLog)logger; - ByteArrayOutputStream logBytes = new ByteArrayOutputStream(); - stdErrLog.setStdErrStream(new PrintStream(logBytes)); + ByteArrayOutputStream logBytes = captureLoggingBytes(() -> + { + Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar); + Object obj = idMap.get("bar"); + assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); + BarNamed bar = (BarNamed)obj; + assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); + }); - Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar); - Object obj = idMap.get("bar"); - assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); - BarNamed bar = (BarNamed)obj; - assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); - - List warnLogs = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) - .filter(line -> line.contains(":WARN")) + List warnings = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) + .filter(line -> line.contains(":WARN :")) .collect(Collectors.toList()); - assertThat("WARN logs size", warnLogs.size(), is(0)); + assertThat("WARN logs size", warnings.size(), is(0)); } @Test @@ -1491,30 +1488,25 @@ public class XmlConfigurationTest " \n" + ""); + ByteArrayOutputStream logBytes = captureLoggingBytes(() -> + { + Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar, xmlAddZed); + Object obj = idMap.get("bar"); + assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); + BarNamed bar = (BarNamed)obj; + assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); + List zeds = bar.getZeds(); + assertThat("BarNamed has zeds", zeds, not(empty())); + assertThat("Zeds[0]", zeds.get(0), is("plain-zero")); + }); - Logger logger = Log.getLogger(XmlConfiguration.class); - assertTrue(logger instanceof StdErrLog); - StdErrLog stdErrLog = (StdErrLog)logger; - ByteArrayOutputStream logBytes = new ByteArrayOutputStream(); - stdErrLog.setStdErrStream(new PrintStream(logBytes)); - - Map idMap = mimicXmlConfigurationMain(xmlFoo, xmlBar, xmlAddZed); - Object obj = idMap.get("bar"); - assertThat("BarNamed instance created", obj, instanceOf(BarNamed.class)); - BarNamed bar = (BarNamed)obj; - assertThat("BarNamed has foo", bar.getFoo(), is("foozball")); - List zeds = bar.getZeds(); - assertThat("BarNamed has zeds", zeds, not(empty())); - assertThat("Zeds[0]", zeds.get(0), is("plain-zero")); - - - List warnLogs = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) - .filter(line -> line.contains(":WARN")) + List warnings = Arrays.stream(logBytes.toString(UTF_8.name()).split(System.lineSeparator())) + .filter(line -> line.contains(":WARN :")) .collect(Collectors.toList()); - assertThat("WARN logs count", warnLogs.size(), is(1)); + assertThat("WARN logs count", warnings.size(), is(1)); - String actualWarn = warnLogs.get(0); + String actualWarn = warnings.get(0); assertThat("WARN logs", actualWarn, allOf(containsString("Ignored arg " + ""); - ByteArrayOutputStream logBytes = null; - Logger logger = Log.getLogger(XmlConfiguration.class); - logger.setDebugEnabled(true); - if (logger instanceof StdErrLog) - { - StdErrLog stdErrLog = (StdErrLog)logger; - logBytes = new ByteArrayOutputStream(); - stdErrLog.setStdErrStream(new PrintStream(logBytes)); - } + ByteArrayOutputStream logBytes = captureLoggingBytes(xmlConfiguration::configure); - xmlConfiguration.configure(); + String[] lines = logBytes.toString(UTF_8.name()).split(System.lineSeparator()); + List warnings = Arrays.stream(lines) + .filter(line -> line.contains(":WARN :")) + .filter(line -> line.contains(testClass.getSimpleName())) + .collect(Collectors.toList()); + // 1. Deprecated constructor + // 2. Deprecated method + // 3. Deprecated method + // 4. Deprecated method + // 5. Deprecated field + // 6. Deprecated field + assertEquals(6, warnings.size()); + } - logger.setDebugEnabled(false); - if (logBytes != null) + private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception + { + Logger slf4jLogger = LoggerFactory.getLogger(XmlConfiguration.class); + Assumptions.assumeTrue(slf4jLogger instanceof JettyLogger); + + ByteArrayOutputStream logBytes = new ByteArrayOutputStream(); + JettyLogger jettyLogger = (JettyLogger)slf4jLogger; + StdErrAppender appender = (StdErrAppender)jettyLogger.getAppender(); + PrintStream oldStream = appender.getStream(); + int oldLevel = jettyLogger.getLevel(); + try { - String[] lines = logBytes.toString(UTF_8.name()).split(System.lineSeparator()); - List warnings = Arrays.stream(lines) - .filter(line -> line.contains(":WARN:")) - .filter(line -> line.contains(testClass.getSimpleName())) - .collect(Collectors.toList()); - // 1. Deprecated constructor - // 2. Deprecated method - // 3. Deprecated method - // 4. Deprecated method - // 5. Deprecated field - // 6. Deprecated field - assertEquals(6, warnings.size()); + // capture events + appender.setStream(new PrintStream(logBytes, true)); + // make sure we are seeing WARN level events + jettyLogger.setLevel(Level.WARN); + + action.run(); } + finally + { + appender.setStream(oldStream); + jettyLogger.setLevel(oldLevel); + } + return logBytes; + } + + private interface ThrowableAction + { + void run() throws Exception; } } diff --git a/jetty-xml/src/test/resources/jetty-logging.properties b/jetty-xml/src/test/resources/jetty-logging.properties index 1759774266b..263223fbcc0 100644 --- a/jetty-xml/src/test/resources/jetty-logging.properties +++ b/jetty-xml/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.xml.LEVEL=WARN org.eclipse.jetty.util.LEVEL=WARN \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51dbde7619f..e277e48e165 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ UTF-8 1.4 8.20 - 1.8.0-beta2 - 2.11.2 - 1.3.0-alpha4 + 2.0.0-alpha1 + 2.13.0 + 1.3.0-alpha5 5.1.1.RELEASE 1.2 4.0.3 @@ -90,6 +90,7 @@ build-resources + jetty-slf4j-impl jetty-ant jetty-util jetty-jmx @@ -476,6 +477,7 @@ ${compiler.source} ${compiler.target} ${compiler.release} + true -Xlint:exports @@ -951,6 +953,11 @@ + + org.eclipse.jetty + jetty-slf4j-impl + ${project.version} + org.eclipse.jetty.toolchain jetty-servlet-api @@ -1339,7 +1346,6 @@ true false true - Tag for release: jetty-${project.version} jetty-documentation/.* examples/.* diff --git a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/logs/LogCondensePackageStringBenchmark.java b/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/logs/LogCondensePackageStringBenchmark.java deleted file mode 100644 index dff79ec4f61..00000000000 --- a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/logs/LogCondensePackageStringBenchmark.java +++ /dev/null @@ -1,65 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.util.log; - -import java.util.concurrent.TimeUnit; - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; -import org.openjdk.jmh.infra.Blackhole; -import org.openjdk.jmh.profile.GCProfiler; -import org.openjdk.jmh.runner.Runner; -import org.openjdk.jmh.runner.RunnerException; -import org.openjdk.jmh.runner.options.Options; -import org.openjdk.jmh.runner.options.OptionsBuilder; - -@Fork(value = 5) -@State(Scope.Benchmark) - -@Warmup(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS) -public class LogCondensePackageStringBenchmark -{ - @Param({ - "com.acme.Dump", - "org.eclipse.jetty.websocket.common.extensions.compress.DeflateFrameExtension$Pool" - }) - String fqClassName; - - @Benchmark - public void testCondensePackage(Blackhole blackhole) - { - blackhole.consume(AbstractLogger.condensePackageString(fqClassName)); - } - - public static void main(String[] args) throws RunnerException - { - Options opt = new OptionsBuilder() - .include(LogCondensePackageStringBenchmark.class.getSimpleName()) - .addProfiler(GCProfiler.class) - .build(); - - new Runner(opt).run(); - } -} diff --git a/tests/jetty-jmh/src/main/resources/jetty-logging.properties b/tests/jetty-jmh/src/main/resources/jetty-logging.properties index 799aa62aed3..ab545e4ab63 100644 --- a/tests/jetty-jmh/src/main/resources/jetty-logging.properties +++ b/tests/jetty-jmh/src/main/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG #org.eclipse.jetty.http.LEVEL=DEBUG diff --git a/tests/test-distribution/pom.xml b/tests/test-distribution/pom.xml index 226903f6e5b..91f1ee72cfb 100644 --- a/tests/test-distribution/pom.xml +++ b/tests/test-distribution/pom.xml @@ -14,10 +14,6 @@ - - org.slf4j - slf4j-simple - org.eclipse.jetty jetty-util diff --git a/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java b/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java index 1e2ea636175..aae25684091 100644 --- a/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java +++ b/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java @@ -65,8 +65,8 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

Helper class to test the Jetty Distribution

. @@ -108,7 +108,7 @@ import org.eclipse.jetty.util.log.Logger; */ public class DistributionTester { - private static final Logger LOGGER = Log.getLogger(DistributionTester.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DistributionTester.class); private Config config; @@ -528,7 +528,7 @@ public class DistributionTester String line; while ((line = reader.readLine()) != null && !stop) { - LOGGER.info("{}", line); + LOGGER.info(line); logs.add(line); } } diff --git a/tests/test-distribution/src/test/resources/jetty-logging.properties b/tests/test-distribution/src/test/resources/jetty-logging.properties index d96a696f82e..56cc73e5d68 100644 --- a/tests/test-distribution/src/test/resources/jetty-logging.properties +++ b/tests/test-distribution/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG diff --git a/tests/test-distribution/src/test/resources/test-realm.xml b/tests/test-distribution/src/test/resources/test-realm.xml index 72c6de06d68..0b4cf7f7c31 100644 --- a/tests/test-distribution/src/test/resources/test-realm.xml +++ b/tests/test-distribution/src/test/resources/test-realm.xml @@ -1,24 +1,29 @@ - + - - - - - - - - - - - Test Realm - - false - - - + + + + + + + + + + + Test Realm + + + + false + + + - - demo test-realm is deployed. DO NOT USE IN PRODUCTION! - + + org.eclipse.jetty + + demo test-realm is deployed. DO NOT USE IN PRODUCTION! + + diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java index 87bfdb5b1b1..c1bd4f8b925 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java @@ -62,6 +62,7 @@ import org.eclipse.jetty.http2.HTTP2Session; import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.client.http.HttpConnectionOverHTTP2; import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpInput; @@ -71,7 +72,6 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler.Context; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.FuturePromise; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java index 1b46c984746..5d45defd73b 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java @@ -44,6 +44,7 @@ import org.eclipse.jetty.http.BadMessageException; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http2.FlowControlStrategy; import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; @@ -51,7 +52,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.BlockingArrayQueue; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; diff --git a/tests/test-http-client-transport/src/test/resources/jetty-logging.properties b/tests/test-http-client-transport/src/test/resources/jetty-logging.properties index 2f142761dd2..2d990e2cc40 100644 --- a/tests/test-http-client-transport/src/test/resources/jetty-logging.properties +++ b/tests/test-http-client-transport/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.fcgi.LEVEL=DEBUG diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DeploymentErrorTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DeploymentErrorTest.java index c75b8079737..8d823d125c9 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DeploymentErrorTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DeploymentErrorTest.java @@ -40,6 +40,7 @@ import org.eclipse.jetty.deploy.providers.WebAppProvider; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.RuntimeIOException; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -52,7 +53,6 @@ import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.Configuration; diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/FailedSelectorTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/FailedSelectorTest.java index f44460d2f26..685b940ec00 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/FailedSelectorTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/FailedSelectorTest.java @@ -47,6 +47,7 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.ManagedSelector; import org.eclipse.jetty.io.SelectorManager; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; @@ -56,7 +57,6 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.Scheduler; import org.junit.jupiter.api.AfterEach; diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java index b184f26d93d..3517b2a2229 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.tools.HttpTester; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.test.support.StringUtil; import org.eclipse.jetty.test.support.XmlBasedJettyServer; import org.eclipse.jetty.test.support.rawhttp.HttpSocket; @@ -39,7 +40,6 @@ import org.eclipse.jetty.test.support.rawhttp.HttpTesting; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.StringAssert; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; diff --git a/tests/test-integration/src/test/resources/jetty-logging.properties b/tests/test-integration/src/test/resources/jetty-logging.properties index f076e496439..c3b261ea39e 100644 --- a/tests/test-integration/src/test/resources/jetty-logging.properties +++ b/tests/test-integration/src/test/resources/jetty-logging.properties @@ -1,5 +1,5 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog +# Jetty Logging using jetty-slf4j-impl +## Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=WARN #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.websocket.LEVEL=DEBUG diff --git a/tests/test-loginservice/src/test/resources/jetty-logging.properties b/tests/test-loginservice/src/test/resources/jetty-logging.properties index adf68c7c337..54cd5fb2936 100644 --- a/tests/test-loginservice/src/test/resources/jetty-logging.properties +++ b/tests/test-loginservice/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG diff --git a/tests/test-quickstart/src/test/resources/jetty-logging.properties b/tests/test-quickstart/src/test/resources/jetty-logging.properties index aec748c60f8..f0e97400975 100644 --- a/tests/test-quickstart/src/test/resources/jetty-logging.properties +++ b/tests/test-quickstart/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=INFO # org.eclipse.jetty.quickstart.AttributeNormalizer.LEVEL=DEBUG diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java index af69255e30c..17bcb26cb33 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java @@ -27,11 +27,10 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.jupiter.api.AfterEach; @@ -100,7 +99,7 @@ public class ReloadedSessionMissingClassTest webApp.addServlet("Bar", "/bar"); server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(ReloadedSessionMissingClassTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/resources/jetty-logging.properties b/tests/test-sessions/test-mongodb-sessions/src/test/resources/jetty-logging.properties index fd2d21f9748..253433cae3a 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/resources/jetty-logging.properties +++ b/tests/test-sessions/test-mongodb-sessions/src/test/resources/jetty-logging.properties @@ -1,4 +1,3 @@ # Setup default logging implementation for during testing -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog - +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.server.LEVEL=DEBUG \ No newline at end of file diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AbstractSessionCacheTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AbstractSessionCacheTest.java index cc8965e2d9d..31704601f43 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AbstractSessionCacheTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AbstractSessionCacheTest.java @@ -20,17 +20,15 @@ package org.eclipse.jetty.server.session; import java.util.Collections; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionActivationListener; import javax.servlet.http.HttpSessionEvent; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -150,7 +148,7 @@ public abstract class AbstractSessionCacheTest context.getSessionHandler().setSessionCache(cache); server.start(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(AbstractSessionCacheTest.class.getPackage())) { //check that session 1234 cannot be read, ie returns null AND //that it is deleted in the datastore diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java index 56de86cd0ba..06fb0b7872d 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java @@ -33,10 +33,9 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -73,7 +72,7 @@ public class AsyncTest server.start(); int port = server.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(AsyncTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -125,7 +124,7 @@ public class AsyncTest server.start(); int port = server.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(AsyncTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -181,7 +180,7 @@ public class AsyncTest server.start(); int port = server.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(AsyncTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -234,7 +233,7 @@ public class AsyncTest server.start(); int port = server.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(AsyncTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -290,10 +289,10 @@ public class AsyncTest server.start(); int port = server.getPort(); HttpClient client = new HttpClient(); - - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + + try (StacklessLogging stackless = new StacklessLogging(AsyncTest.class.getPackage())) { - + client.start(); String url = "http://localhost:" + port + "/ctxA/test?action=asyncComplete"; diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/CreationTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/CreationTest.java index 00e661db79f..a675afa5a10 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/CreationTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/CreationTest.java @@ -33,11 +33,10 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -83,7 +82,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -152,7 +151,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -204,7 +203,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -252,7 +251,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -307,7 +306,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -362,7 +361,7 @@ public class CreationTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(CreationTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DeleteUnloadableSessionTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DeleteUnloadableSessionTest.java index b8aa43e5398..02c1e3edeee 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DeleteUnloadableSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DeleteUnloadableSessionTest.java @@ -31,10 +31,9 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -155,7 +154,7 @@ public class DeleteUnloadableSessionTest ServletHolder holder = new ServletHolder(servlet); context.addServlet(holder, servletMapping); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(DeleteUnloadableSessionTest.class.getPackage())) { server.start(); int port = server.getPort(); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java index a28212f864f..ff4d3f1b5f8 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java @@ -29,11 +29,10 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -62,13 +61,13 @@ public class DuplicateCookieTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(DuplicateCookieTest.class.getPackage())) { //create a valid session createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(), contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(), "4422"); - + client = new HttpClient(); client.start(); @@ -105,7 +104,7 @@ public class DuplicateCookieTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(DuplicateCookieTest.class.getPackage())) { //create a valid session createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(), @@ -152,7 +151,7 @@ public class DuplicateCookieTest server1.start(); int port1 = server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(DuplicateCookieTest.class.getPackage())) { //create some of unexpired sessions createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(), diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java index a84d0e7b210..a1b91471d98 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/IdleSessionTest.java @@ -30,10 +30,9 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.util.thread.AutoLock; import org.junit.jupiter.api.Test; @@ -84,7 +83,7 @@ public class IdleSessionTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(IdleSessionTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); @@ -210,7 +209,7 @@ public class IdleSessionTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(IdleSessionTest.class.getPackage())) { HttpClient client = new HttpClient(); client.start(); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java index 13429da6391..ef210fcc9d3 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java @@ -29,11 +29,10 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -81,7 +80,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try @@ -131,7 +130,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try @@ -214,7 +213,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try @@ -304,7 +303,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try @@ -399,7 +398,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try @@ -478,7 +477,7 @@ public class SaveOptimizeTest _server1.start(); int port1 = _server1.getPort(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SaveOptimizeTest.class.getPackage())) { HttpClient client = new HttpClient(); try diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionEvictionFailureTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionEvictionFailureTest.java index e602959df49..fd55f277dfa 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionEvictionFailureTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionEvictionFailureTest.java @@ -30,10 +30,9 @@ import javax.servlet.http.HttpSession; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -176,7 +175,7 @@ public class SessionEvictionFailureTest int port1 = server.getPort(); HttpClient client = new HttpClient(); client.start(); - try (StacklessLogging stackless = new StacklessLogging(Log.getLogger("org.eclipse.jetty.server.session"))) + try (StacklessLogging stackless = new StacklessLogging(SessionEvictionFailureTest.class.getPackage())) { String url = "http://localhost:" + port1 + contextPath + servletMapping; diff --git a/tests/test-sessions/test-sessions-common/src/test/resources/jetty-logging.properties b/tests/test-sessions/test-sessions-common/src/test/resources/jetty-logging.properties index d96a696f82e..56cc73e5d68 100644 --- a/tests/test-sessions/test-sessions-common/src/test/resources/jetty-logging.properties +++ b/tests/test-sessions/test-sessions-common/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl #org.eclipse.jetty.LEVEL=DEBUG diff --git a/tests/test-webapps/test-http2-webapp/src/test/resources/jetty-logging.properties b/tests/test-webapps/test-http2-webapp/src/test/resources/jetty-logging.properties index 055e90b60ef..fe35fe0c739 100644 --- a/tests/test-webapps/test-http2-webapp/src/test/resources/jetty-logging.properties +++ b/tests/test-webapps/test-http2-webapp/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl org.eclipse.jetty.LEVEL=INFO #org.eclipse.jetty.alpn.LEVEL=DEBUG diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml index 0f9867548b9..0b4cf7f7c31 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml +++ b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml @@ -1,24 +1,29 @@ - - - - - - - - - - - Test Realm - - false - - - + + + + + + + + + + + Test Realm + + + + false + + + - - demo test-realm is deployed. DO NOT USE IN PRODUCTION! - + + org.eclipse.jetty + + demo test-realm is deployed. DO NOT USE IN PRODUCTION! + + diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index 9d34984b173..30b8d52bde0 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -49,7 +49,6 @@ import org.eclipse.jetty.server.session.DefaultSessionCache; import org.eclipse.jetty.server.session.FileSessionDataStore; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.MetaInfConfiguration; @@ -63,8 +62,6 @@ public class TestServer public static void main(String[] args) throws Exception { - ((StdErrLog)Log.getLog()).setSource(false); - // TODO don't depend on this file structure Path jettyRoot = FileSystems.getDefault().getPath(".").toAbsolutePath().normalize(); if (!Files.exists(jettyRoot.resolve("VERSION.txt"))) diff --git a/tests/test-webapps/test-jetty-webapp/src/test/resources/jetty-logging.properties b/tests/test-webapps/test-jetty-webapp/src/test/resources/jetty-logging.properties index 606fca83005..04724735a9d 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/resources/jetty-logging.properties +++ b/tests/test-webapps/test-jetty-webapp/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +# Jetty Logging using jetty-slf4j-impl com.acme.LEVEL=INFO # org.eclipse.jetty.annotations.LEVEL=DEBUG \ No newline at end of file diff --git a/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java b/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java index 844b756c225..697941589c9 100644 --- a/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java +++ b/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/TestTransparentProxyServer.java @@ -36,7 +36,6 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.WebAppContext; @@ -47,8 +46,6 @@ public class TestTransparentProxyServer { public static void main(String[] args) throws Exception { - ((StdErrLog)Log.getLog()).setSource(false); - String jettyRoot = "../../.."; // Setup Threadpool