From 0ffaf2f20e72e743a7438aabc03f4c395cca01a6 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Fri, 6 Dec 2024 19:39:54 +0800 Subject: [PATCH] refactor: rename ExceptionReporter to ExceptionLogger; and rename related system property name --- ...tionReporter.java => ExceptionLogger.java} | 38 +++++++++++++------ .../src/main/java/io/foldright/cffu/LLCF.java | 6 +-- scripts/integration_test | 8 ++-- 3 files changed, 34 insertions(+), 18 deletions(-) rename cffu-core/src/main/java/io/foldright/cffu/{ExceptionReporter.java => ExceptionLogger.java} (55%) diff --git a/cffu-core/src/main/java/io/foldright/cffu/ExceptionReporter.java b/cffu-core/src/main/java/io/foldright/cffu/ExceptionLogger.java similarity index 55% rename from cffu-core/src/main/java/io/foldright/cffu/ExceptionReporter.java rename to cffu-core/src/main/java/io/foldright/cffu/ExceptionLogger.java index 49c7c210..9da63557 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/ExceptionReporter.java +++ b/cffu-core/src/main/java/io/foldright/cffu/ExceptionLogger.java @@ -1,32 +1,48 @@ package io.foldright.cffu; import edu.umd.cs.findbugs.annotations.Nullable; +import org.jetbrains.annotations.Contract; import org.slf4j.spi.LocationAwareLogger; /** - * Errors should never pass silently. Unless explicitly silenced. + * Internal exception logging utility for the cffu library. + *

+ * By default, uncaught exceptions are logged with their complete stack traces. The logging behavior can be configured + * through the system property {@code cffu.uncaught.exception.log.format} with the following values: + *

+ *

+ * Configure the logging format by either: + *

* * @author HuHao (995483610 at qq dot com) * @author Jerry Lee (oldratlee at gmail dot com) + * @see Errors should never pass silently. Unless explicitly silenced. */ -final class ExceptionReporter { - private static final String FQCN = ExceptionReporter.class.getName(); +final class ExceptionLogger { + private static final String FQCN = ExceptionLogger.class.getName(); private static final String CFFU_PACKAGE_NAME = FQCN.replaceFirst("\\.[^.]*$", ""); private static final LoggerAdapter logger = getLogger(); @SuppressWarnings("StatementWithEmptyBody") - static void reportUncaughtException(String where, Throwable ex) { - final String fullReport = "full"; - final String shortReport = "short"; - final String noneReport = "none"; + static void logUncaughtException(String where, Throwable ex) { + final String fullFormat = "full"; + final String shortFormat = "short"; + final String noneFormat = "none"; - final String report = System.getProperty("cffu.uncaught.exception.report", fullReport); + final String format = System.getProperty("cffu.uncaught.exception.log.format", fullFormat); final String msgHead = "Uncaught exception occurred at "; - if (noneReport.equalsIgnoreCase(report)) { + if (noneFormat.equalsIgnoreCase(format)) { // pass silently when explicitly silenced. - } else if (shortReport.equalsIgnoreCase(report)) { + } else if (shortFormat.equalsIgnoreCase(format)) { logger.error(msgHead + where + ", " + ex, null); } else { logger.error(msgHead + where, ex); @@ -67,6 +83,6 @@ public void error(String msg, @Nullable Throwable ex) { } } - private ExceptionReporter() { + private ExceptionLogger() { } } diff --git a/cffu-core/src/main/java/io/foldright/cffu/LLCF.java b/cffu-core/src/main/java/io/foldright/cffu/LLCF.java index 7cffff9a..873b8d2c 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/LLCF.java +++ b/cffu-core/src/main/java/io/foldright/cffu/LLCF.java @@ -12,7 +12,7 @@ import java.util.function.BiConsumer; import java.util.function.Supplier; -import static io.foldright.cffu.ExceptionReporter.reportUncaughtException; +import static io.foldright.cffu.ExceptionLogger.logUncaughtException; import static io.foldright.cffu.InternalCommonUtils.mapArray; import static java.util.Objects.requireNonNull; import static java.util.concurrent.CompletableFuture.completedFuture; @@ -150,7 +150,7 @@ C peek0(C cfThis, BiConsumer action, String where) action.accept(v, ex); } catch (Throwable e) { if (ex != null) e.addSuppressed(ex); - reportUncaughtException(where, e); + logUncaughtException(where, e); } }); return cfThis; @@ -170,7 +170,7 @@ C peekAsync0(C cfThis, BiConsumer action, String w action.accept(v, ex); } catch (Throwable e) { if (ex != null) e.addSuppressed(ex); - reportUncaughtException(where, e); + logUncaughtException(where, e); } }, executor); return cfThis; diff --git a/scripts/integration_test b/scripts/integration_test index 797cbd03..bace4479 100755 --- a/scripts/integration_test +++ b/scripts/integration_test @@ -65,23 +65,23 @@ mvu::mvn_cmd clean install readonly MVN_OPTS_FOR_JAVA8=( -Dkotlin.version=1.6.0 -Dguava.version=29.0-jre -P!default-logging-dependencies -P!default-arch-unit-test - -Dcffu.uncaught.exception.report=short + -Dcffu.uncaught.exception.log.format=short ) # shellcheck disable=SC2034 readonly MVN_OPTS_FOR_JAVA11=( -Dkotlin.version=1.7.0 -DswitchToLog4j2LoggingDependencies -Pswitch-slf4j-to-v1 - -Dcffu.uncaught.exception.report=short + -Dcffu.uncaught.exception.log.format=short ) # shellcheck disable=SC2034 readonly MVN_OPTS_FOR_JAVA17=( -Dkotlin.version=1.8.0 - -DswitchToLog4j2LoggingDependencies -Dcffu.uncaught.exception.report=short + -DswitchToLog4j2LoggingDependencies -Dcffu.uncaught.exception.log.format=short ) # shellcheck disable=SC2034 readonly MVN_OPTS_FOR_JAVA23=( -Dkotlin.version=1.9.0 - -Dcffu.uncaught.exception.report=none + -Dcffu.uncaught.exception.log.format=none ) SUREFIRE_TEST_GOAL=(surefire:test)