Skip to content

Commit

Permalink
[improve][dependency] Remove jul-to-slf4j (apache#16320)
Browse files Browse the repository at this point in the history
### Motivation

see also https://lists.apache.org/thread/65skwo492w2nfjwhb3d9y51roq13h8bs

PulsarAdminImpl has a static block requires classpath contains exact either of:

* slf4j-jdk14
* jul-to-slf4j

It causes an issue that if user depends on neither slf4j-jdk14 nor jul-to-slf4j, PulsarAdminImpl will panic with NoClassDefFoundError. And thus, user should add one of them (basically jul-to-slf4j) even if they don't depend on it effectively.

### Modifications

Remove jul-to-slf4j from all modules under Pulsar.

The Pulsar project uses slf4j as the logging facade consistently. If a user want to add a dependency using a different logging framework, they should take care of the packaging strategy themselves.

pulsar-sql has a dependency to slf4j-jdk14 which redirect slf4j to jul. Since this is a unidirectional redirection, it won't cause runtime error, but pulsar-sql will logging with jul framework, which is the same as with previous workaround.
  • Loading branch information
tisonkun authored and weimob-wuxuanqi committed Jul 14, 2022
1 parent 75678bd commit 60f2cd4
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 58 deletions.
1 change: 0 additions & 1 deletion distribution/server/src/assemble/LICENSE.bin.txt
Expand Up @@ -558,7 +558,6 @@ BSD 2-Clause License
MIT License
* Java SemVer -- com.github.zafarkhaja-java-semver-0.9.0.jar -- licenses/LICENSE-SemVer.txt
* SLF4J -- licenses/LICENSE-SLF4J.txt
- org.slf4j-jul-to-slf4j-1.7.32.jar
- org.slf4j-slf4j-api-1.7.32.jar
- org.slf4j-jcl-over-slf4j-1.7.32.jar
* The Checker Framework
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -691,12 +691,6 @@ flexible messaging model and an intuitive client API.</description>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions pulsar-broker/pom.xml
Expand Up @@ -267,11 +267,6 @@
<artifactId>jackson-module-jsonSchema</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand Down
Expand Up @@ -62,13 +62,10 @@
import org.apache.pulsar.functions.worker.service.WorkerServiceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

public class PulsarBrokerStarter {

private static ServiceConfiguration loadConfig(String configFile) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
try (InputStream inputStream = new FileInputStream(configFile)) {
ServiceConfiguration config = create(inputStream, ServiceConfiguration.class);
// it validates provided configuration is completed
Expand Down
5 changes: 0 additions & 5 deletions pulsar-client-admin/pom.xml
Expand Up @@ -92,11 +92,6 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Expand Up @@ -65,7 +65,6 @@
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

/**
* Pulsar client admin API client.
Expand Down Expand Up @@ -114,24 +113,6 @@ public class PulsarAdminImpl implements PulsarAdmin {
private final int requestTimeout;
private final TimeUnit requestTimeoutUnit;

static {
/**
* The presence of slf4j-jdk14.jar, that is the jul binding for SLF4J, will force SLF4J calls to be delegated to
* jul. On the other hand, the presence of jul-to-slf4j.jar, plus the installation of SLF4JBridgeHandler, by
* invoking "SLF4JBridgeHandler.install()" will route jul records to SLF4J. Thus, if both jar are present
* simultaneously (and SLF4JBridgeHandler is installed), slf4j calls will be delegated to jul and jul records
* will be routed to SLF4J, resulting in an endless loop. We avoid this loop by detecting if slf4j-jdk14 is used
* in the client class path. If slf4j-jdk14 is found, we don't use the slf4j bridge.
*/
try {
Class.forName("org.slf4j.impl.JDK14LoggerFactory");
} catch (Exception ex) {
// Setup the bridge for java.util.logging to SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
}

public PulsarAdminImpl(String serviceUrl, ClientConfigurationData clientConfigData) throws PulsarClientException {
this(serviceUrl, clientConfigData, DEFAULT_CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS,
DEFAULT_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS, DEFAULT_REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS,
Expand Down
5 changes: 0 additions & 5 deletions pulsar-proxy/pom.xml
Expand Up @@ -125,11 +125,6 @@
<artifactId>javax.activation</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
Expand Down
Expand Up @@ -23,8 +23,6 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.pulsar.common.stats.JvmMetrics.getJvmDirectMemoryUsed;
import static org.slf4j.bridge.SLF4JBridgeHandler.install;
import static org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -107,11 +105,6 @@ public class ProxyServiceStarter {

public ProxyServiceStarter(String[] args) throws Exception {
try {

// setup handlers
removeHandlersForRootLogger();
install();

DateFormat dateFormat = new SimpleDateFormat(
FixedDateFormat.FixedFormat.ISO8601_OFFSET_DATE_TIME_HHMM.getPattern());
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
Expand Down
2 changes: 0 additions & 2 deletions pulsar-sql/presto-distribution/LICENSE
Expand Up @@ -508,8 +508,6 @@ MIT License
- slf4j-jdk14-1.7.32.jar
* JCL 1.2 Implemented Over SLF4J
- jcl-over-slf4j-1.7.32.jar
* JUL to SLF4J Bridge
- jul-to-slf4j-1.7.32.jar
* Checker Qual
- checker-qual-3.12.0.jar
* Annotations
Expand Down
5 changes: 0 additions & 5 deletions pulsar-websocket/pom.xml
Expand Up @@ -87,11 +87,6 @@
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>

<!-- To write basic websockets against -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
Expand Down

0 comments on commit 60f2cd4

Please sign in to comment.