Skip to content

Commit

Permalink
Issue #4572 - Replace Jetty Logging with SLF4J
Browse files Browse the repository at this point in the history
* Introducing jetty-slf4j-impl
* Make Jetty use org.slf4j
* Removed most of org.eclipse.jetty.util.log classes
* Left org.eclipse.jetty.util.log.Log and
       org.eclipse.jetty.util.log.Logger but as
  simple bridge classes that are deprecated
* Migrated code using org.eclipse.jetty.util.log.StacklessLogging
  to org.eclipse.jetty.logging.StacklessLogging found in
  the jetty-slf4j-impl
* Moved logging start modules from jetty-util to jetty-home
* Simplified logging start modules
* Updated code that was using StdErrLog directly
* Updating module-info.java for org.slf4j
* removing org.eclipse.jetty.util.log.class references
* jetty-start supports manually declared default provider
  + and we use it to default "logging" to the "logging-jetty" provider
* Cleaning up jetty-maven-plugin and IT testing for Logging
* Using old slf4j for it testing
* Updating compiler config to show Xlint:exports warnings
* Updating console-capture and logging-noop
* Adding slf4j bridge (capture) jetty modules
* Updates to jetty logging module locations
* Changing reference to slf4j dependent mod
* Process requested enabled modules in topological order
* Limiting inclusions in shaded jetty-start
  + Also adding note to jetty-util classes that are used by
    jetty-start
* Default logging level on baseline logging config is INFO (not DEBUG)
* Changing from system to server classes in logging
* Updating other modules to use new logging names

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Mar 16, 2020
1 parent 5148bee commit 8b7e649
Show file tree
Hide file tree
Showing 319 changed files with 4,422 additions and 5,514 deletions.
4 changes: 4 additions & 0 deletions apache-jsp/pom.xml
Expand Up @@ -63,6 +63,10 @@
</build>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
Expand Down
1 change: 1 addition & 0 deletions apache-jsp/src/main/java/module-info.java
Expand Up @@ -29,6 +29,7 @@

requires java.xml;
requires jetty.servlet.api;
requires org.slf4j;
requires org.eclipse.jetty.util;
requires org.mortbay.apache.jasper;

Expand Down
21 changes: 10 additions & 11 deletions apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JuliLog.java
Expand Up @@ -18,26 +18,25 @@

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)
{
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
Expand All @@ -49,31 +48,31 @@ public boolean isDebugEnabled()
@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
Expand Down
2 changes: 1 addition & 1 deletion 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
8 changes: 8 additions & 0 deletions examples/embedded/pom.xml
Expand Up @@ -15,6 +15,14 @@
<bundle-symbolic-name>${project.groupId}.embedded</bundle-symbolic-name>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util-ajax</artifactId>
Expand Down
@@ -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
Expand Down
@@ -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
Expand Down
Expand Up @@ -23,6 +23,7 @@
exports org.eclipse.jetty.alpn.client;

requires transitive org.eclipse.jetty.io;
requires org.slf4j;

uses ALPNProcessor.Client;
}
Expand Up @@ -23,6 +23,7 @@
{
requires org.conscrypt;
requires transitive org.eclipse.jetty.alpn.client;
requires org.slf4j;

provides ALPNProcessor.Client with ConscryptClientALPNProcessor;
}
@@ -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
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down
@@ -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
Expand Up @@ -22,6 +22,7 @@
module org.eclipse.jetty.alpn.java.client
{
requires transitive org.eclipse.jetty.alpn.client;
requires org.slf4j;

provides ALPNProcessor.Client with JDK9ClientALPNProcessor;
}
@@ -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
Expand Up @@ -21,6 +21,7 @@

module org.eclipse.jetty.alpn.java.server
{
requires org.slf4j;
requires transitive org.eclipse.jetty.alpn.server;

provides ALPNProcessor.Server with JDK9ServerALPNProcessor;
Expand Down
@@ -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
Expand Up @@ -23,6 +23,7 @@
exports org.eclipse.jetty.alpn.server;

requires transitive org.eclipse.jetty.server;
requires org.slf4j;

uses ALPNProcessor.Server;
}
1 change: 1 addition & 0 deletions jetty-annotations/src/main/java/module-info.java
Expand Up @@ -29,6 +29,7 @@
requires java.naming;
requires transitive org.eclipse.jetty.plus;
requires transitive org.objectweb.asm;
requires org.slf4j;

uses ServletContainerInitializer;

Expand Down
Expand Up @@ -20,10 +20,10 @@

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;
Expand Down
@@ -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
6 changes: 2 additions & 4 deletions jetty-client/pom.xml
Expand Up @@ -24,7 +24,6 @@
@{argLine} ${jetty.surefire.argLine}
--add-modules java.security.jgss
--add-modules org.eclipse.jetty.jmx
--add-modules org.slf4j
</argLine>
</configuration>
</plugin>
Expand Down Expand Up @@ -157,11 +156,10 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions jetty-client/src/main/java/module-info.java
Expand Up @@ -28,6 +28,7 @@

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;
Expand Down
Expand Up @@ -82,6 +82,7 @@
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;
Expand All @@ -92,7 +93,6 @@
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;
Expand Down
Expand Up @@ -35,9 +35,9 @@
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;
Expand Down
Expand Up @@ -33,9 +33,9 @@
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;

Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
4 changes: 4 additions & 0 deletions jetty-deploy/pom.xml
Expand Up @@ -51,6 +51,10 @@
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
Expand Down
1 change: 1 addition & 0 deletions jetty-deploy/src/main/java/module-info.java
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -33,12 +34,11 @@
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;
Expand Down Expand Up @@ -103,10 +103,9 @@ public void testBadAppThrowOnUnavailableTrueXmlOrder() throws Exception

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"));
Expand Down Expand Up @@ -157,9 +156,9 @@ public void testBadAppThrowOnUnavailableTrueEmbeddedOrder() throws Exception
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"));
Expand Down
2 changes: 1 addition & 1 deletion 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
1 change: 1 addition & 0 deletions jetty-fcgi/fcgi-client/src/main/java/module-info.java
Expand Up @@ -24,4 +24,5 @@
exports org.eclipse.jetty.fcgi.parser;

requires transitive org.eclipse.jetty.client;
requires org.slf4j;
}
@@ -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
4 changes: 4 additions & 0 deletions jetty-fcgi/fcgi-server/pom.xml
Expand Up @@ -15,6 +15,10 @@
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-servlet-api</artifactId>
Expand Down
1 change: 1 addition & 0 deletions jetty-fcgi/fcgi-server/src/main/java/module-info.java
Expand Up @@ -21,6 +21,7 @@
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;

Expand Down
Expand Up @@ -260,7 +260,7 @@ protected void customize(Request request, HttpFields fastCGIHeaders)
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)));
}
Expand Down

0 comments on commit 8b7e649

Please sign in to comment.