This is an automated email from the ASF dual-hosted git repository. dongjoon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new de8ba8589c21 [SPARK-48145][CORE] Remove logDebug and logTrace with MDC in JAVA structured logging framework de8ba8589c21 is described below commit de8ba8589c218ffbe57efc581bd921a6aef73fae Author: Gengliang Wang <gengli...@apache.org> AuthorDate: Mon May 6 13:32:54 2024 -0700 [SPARK-48145][CORE] Remove logDebug and logTrace with MDC in JAVA structured logging framework ### What changes were proposed in this pull request? Since we are targeting on migration INFO/WARN/ERROR level logs to structure logging, this PR removes the logDebug and logTrace methods from the JAVA structured logging framework. ### Why are the changes needed? In the log migration PR https://github.com/apache/spark/pull/46390, there are unnecessary changes such as updating ``` logger.debug("Task {} need to spill {} for {}", taskAttemptId, Utils.bytesToString(required - got), requestingConsumer); ``` to ``` LOGGER.debug("Task {} need to spill {} for {}", String.valueOf(taskAttemptId), Utils.bytesToString(required - got), requestingConsumer.toString()); ``` With this PR, we can avoid such changes during log migrations. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing UT. ### Was this patch authored or co-authored using generative AI tooling? No Closes #46405 from gengliangwang/updateJavaLog. Authored-by: Gengliang Wang <gengli...@apache.org> Signed-off-by: Dongjoon Hyun <dh...@apple.com> --- .../java/org/apache/spark/internal/Logger.java | 49 ++++++++++------------ .../org/apache/spark/util/LoggerSuiteBase.java | 28 +++---------- 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/common/utils/src/main/java/org/apache/spark/internal/Logger.java b/common/utils/src/main/java/org/apache/spark/internal/Logger.java index f252f44b3b76..2b4dd3bb45bc 100644 --- a/common/utils/src/main/java/org/apache/spark/internal/Logger.java +++ b/common/utils/src/main/java/org/apache/spark/internal/Logger.java @@ -110,50 +110,43 @@ public class Logger { slf4jLogger.debug(msg); } - public void debug(String msg, Throwable throwable) { - slf4jLogger.debug(msg, throwable); + public void debug(String format, Object arg) { + slf4jLogger.debug(format, arg); } - public void debug(String msg, MDC... mdcs) { - if (mdcs == null || mdcs.length == 0) { - slf4jLogger.debug(msg); - } else if (slf4jLogger.isDebugEnabled()) { - withLogContext(msg, mdcs, null, mt -> slf4jLogger.debug(mt.message)); - } + public void debug(String format, Object arg1, Object arg2) { + slf4jLogger.debug(format, arg1, arg2); } - public void debug(String msg, Throwable throwable, MDC... mdcs) { - if (mdcs == null || mdcs.length == 0) { - slf4jLogger.debug(msg); - } else if (slf4jLogger.isDebugEnabled()) { - withLogContext(msg, mdcs, throwable, mt -> slf4jLogger.debug(mt.message, mt.throwable)); - } + public void debug(String format, Object... arguments) { + slf4jLogger.debug(format, arguments); + } + + public void debug(String msg, Throwable throwable) { + slf4jLogger.debug(msg, throwable); } public void trace(String msg) { slf4jLogger.trace(msg); } - public void trace(String msg, Throwable throwable) { - slf4jLogger.trace(msg, throwable); + public void trace(String format, Object arg) { + slf4jLogger.trace(format, arg); } - public void trace(String msg, MDC... mdcs) { - if (mdcs == null || mdcs.length == 0) { - slf4jLogger.trace(msg); - } else if (slf4jLogger.isTraceEnabled()) { - withLogContext(msg, mdcs, null, mt -> slf4jLogger.trace(mt.message)); - } + public void trace(String format, Object arg1, Object arg2) { + slf4jLogger.trace(format, arg1, arg2); } - public void trace(String msg, Throwable throwable, MDC... mdcs) { - if (mdcs == null || mdcs.length == 0) { - slf4jLogger.trace(msg); - } else if (slf4jLogger.isTraceEnabled()) { - withLogContext(msg, mdcs, throwable, mt -> slf4jLogger.trace(mt.message, mt.throwable)); - } + public void trace(String format, Object... arguments) { + slf4jLogger.trace(format, arguments); } + public void trace(String msg, Throwable throwable) { + slf4jLogger.trace(msg, throwable); + } + + private void withLogContext( String pattern, MDC[] mdcs, diff --git a/common/utils/src/test/java/org/apache/spark/util/LoggerSuiteBase.java b/common/utils/src/test/java/org/apache/spark/util/LoggerSuiteBase.java index cdc06f6fc261..6c39304bece0 100644 --- a/common/utils/src/test/java/org/apache/spark/util/LoggerSuiteBase.java +++ b/common/utils/src/test/java/org/apache/spark/util/LoggerSuiteBase.java @@ -145,9 +145,7 @@ public abstract class LoggerSuiteBase { List.of( Pair.of(Level.ERROR, errorFn), Pair.of(Level.WARN, warnFn), - Pair.of(Level.INFO, infoFn), - Pair.of(Level.DEBUG, debugFn), - Pair.of(Level.TRACE, traceFn)).forEach(pair -> { + Pair.of(Level.INFO, infoFn)).forEach(pair -> { try { assert (captureLogOutput(pair.getRight()).matches( expectedPatternForMsgWithMDC(pair.getLeft()))); @@ -162,14 +160,10 @@ public abstract class LoggerSuiteBase { Runnable errorFn = () -> logger().error(msgWithMDCs, mdcs); Runnable warnFn = () -> logger().warn(msgWithMDCs, mdcs); Runnable infoFn = () -> logger().info(msgWithMDCs, mdcs); - Runnable debugFn = () -> logger().debug(msgWithMDCs, mdcs); - Runnable traceFn = () -> logger().trace(msgWithMDCs, mdcs); List.of( Pair.of(Level.ERROR, errorFn), Pair.of(Level.WARN, warnFn), - Pair.of(Level.INFO, infoFn), - Pair.of(Level.DEBUG, debugFn), - Pair.of(Level.TRACE, traceFn)).forEach(pair -> { + Pair.of(Level.INFO, infoFn)).forEach(pair -> { try { assert (captureLogOutput(pair.getRight()).matches( expectedPatternForMsgWithMDCs(pair.getLeft()))); @@ -185,14 +179,10 @@ public abstract class LoggerSuiteBase { Runnable errorFn = () -> logger().error(msgWithMDCs, exception, mdcs); Runnable warnFn = () -> logger().warn(msgWithMDCs, exception, mdcs); Runnable infoFn = () -> logger().info(msgWithMDCs, exception, mdcs); - Runnable debugFn = () -> logger().debug(msgWithMDCs, exception, mdcs); - Runnable traceFn = () -> logger().trace(msgWithMDCs, exception, mdcs); List.of( Pair.of(Level.ERROR, errorFn), Pair.of(Level.WARN, warnFn), - Pair.of(Level.INFO, infoFn), - Pair.of(Level.DEBUG, debugFn), - Pair.of(Level.TRACE, traceFn)).forEach(pair -> { + Pair.of(Level.INFO, infoFn)).forEach(pair -> { try { assert (captureLogOutput(pair.getRight()).matches( expectedPatternForMsgWithMDCsAndException(pair.getLeft()))); @@ -207,14 +197,10 @@ public abstract class LoggerSuiteBase { Runnable errorFn = () -> logger().error(msgWithMDC, executorIDMDCValueIsNull); Runnable warnFn = () -> logger().warn(msgWithMDC, executorIDMDCValueIsNull); Runnable infoFn = () -> logger().info(msgWithMDC, executorIDMDCValueIsNull); - Runnable debugFn = () -> logger().debug(msgWithMDC, executorIDMDCValueIsNull); - Runnable traceFn = () -> logger().trace(msgWithMDC, executorIDMDCValueIsNull); List.of( Pair.of(Level.ERROR, errorFn), Pair.of(Level.WARN, warnFn), - Pair.of(Level.INFO, infoFn), - Pair.of(Level.DEBUG, debugFn), - Pair.of(Level.TRACE, traceFn)).forEach(pair -> { + Pair.of(Level.INFO, infoFn)).forEach(pair -> { try { assert (captureLogOutput(pair.getRight()).matches( expectedPatternForMsgWithMDCValueIsNull(pair.getLeft()))); @@ -229,14 +215,10 @@ public abstract class LoggerSuiteBase { Runnable errorFn = () -> logger().error("{}", externalSystemCustomLog); Runnable warnFn = () -> logger().warn("{}", externalSystemCustomLog); Runnable infoFn = () -> logger().info("{}", externalSystemCustomLog); - Runnable debugFn = () -> logger().debug("{}", externalSystemCustomLog); - Runnable traceFn = () -> logger().trace("{}", externalSystemCustomLog); List.of( Pair.of(Level.ERROR, errorFn), Pair.of(Level.WARN, warnFn), - Pair.of(Level.INFO, infoFn), - Pair.of(Level.DEBUG, debugFn), - Pair.of(Level.TRACE, traceFn)).forEach(pair -> { + Pair.of(Level.INFO, infoFn)).forEach(pair -> { try { assert (captureLogOutput(pair.getRight()).matches( expectedPatternForExternalSystemCustomLogKey(pair.getLeft()))); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org