From 8ca7f88985258507517f98aa8eb5d4fb8a9d5396 Mon Sep 17 00:00:00 2001 From: houxiaoyu Date: Sun, 28 Jul 2024 16:32:54 +0800 Subject: [PATCH] remove log4j dependency --- bookkeeper-common/pom.xml | 4 ---- .../bookkeeper/common/component/ComponentStarter.java | 6 ++---- .../org/apache/bookkeeper/replication/AutoRecoveryMain.java | 5 +++-- .../src/main/java/org/apache/bookkeeper/server/Main.java | 5 +++-- .../org/apache/bookkeeper/stream/server/StorageServer.java | 5 +++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/bookkeeper-common/pom.xml b/bookkeeper-common/pom.xml index 0a3ef64b938..aa733d20ff9 100644 --- a/bookkeeper-common/pom.xml +++ b/bookkeeper-common/pom.xml @@ -25,10 +25,6 @@ bookkeeper-common Apache BookKeeper :: Common - - org.apache.logging.log4j - log4j-api - org.apache.bookkeeper.stats bookkeeper-stats-api diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java index b99a805933e..d1cb08163c5 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java @@ -21,7 +21,6 @@ import java.util.concurrent.CompletableFuture; import lombok.extern.slf4j.Slf4j; import org.apache.bookkeeper.common.concurrent.FutureUtils; -import org.apache.logging.log4j.LogManager; /** * Utils to start components. @@ -51,8 +50,6 @@ public void run() { log.error("Failed to close component {} in shutdown hook gracefully, Exiting anyway", component.getName(), e); future.completeExceptionally(e); - } finally { - LogManager.shutdown(); } } @@ -77,8 +74,9 @@ public static CompletableFuture startComponent(LifecycleComponent componen component.setExceptionHandler((t, e) -> { log.error("Triggered exceptionHandler of Component: {} because of Exception in Thread: {}", component.getName(), t, e); + System.err.println(e.getMessage()); // start the shutdown hook when an uncaught exception happen in the lifecycle component. - FutureUtils.complete(future, null); + shutdownHookThread.start(); }); component.publishInfo(new ComponentInfoPublisher()); diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java index cdc0f830f99..926aef43241 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java @@ -56,7 +56,6 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.configuration.ConfigurationException; -import org.apache.logging.log4j.LogManager; import org.apache.zookeeper.KeeperException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -340,7 +339,7 @@ static int doMain(String[] args) { server = buildAutoRecoveryServer(new BookieConfiguration(conf)); } catch (Exception e) { LOG.error("Failed to build AutoRecovery Server", e); - LogManager.shutdown(); + System.err.println(e.getMessage()); return ExitCode.SERVER_EXCEPTION; } @@ -351,8 +350,10 @@ static int doMain(String[] args) { Thread.currentThread().interrupt(); // the server is interrupted LOG.info("AutoRecovery server is interrupted. Exiting ..."); + System.err.println(ie.getMessage()); } catch (ExecutionException ee) { LOG.error("Error in bookie shutdown", ee.getCause()); + System.err.println(ee.getMessage()); return ExitCode.SERVER_EXCEPTION; } return ExitCode.OK; diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/Main.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/Main.java index c97f1e3e1a2..0f73100c050 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/Main.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/Main.java @@ -41,7 +41,6 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.configuration.ConfigurationException; -import org.apache.logging.log4j.LogManager; /** * A bookie server is a server that run bookie and serving rpc requests. @@ -223,7 +222,7 @@ static int doMain(String[] args) { server = buildBookieServer(new BookieConfiguration(conf)); } catch (Exception e) { log.error("Failed to build bookie server", e); - LogManager.shutdown(); + System.err.println(e.getMessage()); return ExitCode.SERVER_EXCEPTION; } @@ -234,8 +233,10 @@ static int doMain(String[] args) { Thread.currentThread().interrupt(); // the server is interrupted log.info("Bookie server is interrupted. Exiting ..."); + System.err.println(ie.getMessage()); } catch (ExecutionException ee) { log.error("Error in bookie shutdown", ee.getCause()); + System.err.println(ee.getMessage()); return ExitCode.SERVER_EXCEPTION; } return ExitCode.OK; diff --git a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java index 6c3596c77e2..d0888b3b1d2 100644 --- a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java +++ b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java @@ -78,7 +78,6 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.distributedlog.DistributedLogConfiguration; -import org.apache.logging.log4j.LogManager; /** * A storage server is a server that run storage service and serving rpc requests. @@ -171,7 +170,7 @@ static int doMain(String[] args) { grpcUseHostname); } catch (Exception e) { log.error("Invalid storage configuration", e); - LogManager.shutdown(); + System.err.println(e.getMessage()); return ExitCode.INVALID_CONF.code(); } @@ -183,8 +182,10 @@ static int doMain(String[] args) { // the server is interrupted. Thread.currentThread().interrupt(); log.info("Storage server is interrupted. Exiting ..."); + System.err.println(e.getMessage()); } catch (ExecutionException e) { log.info("Storage server is exiting ..."); + System.err.println(e.getMessage()); } return ExitCode.OK.code(); }