Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions common/utils/src/main/java/org/apache/spark/internal/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,50 +110,43 @@ public void debug(String msg) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public void testLoggerWithMDC() {
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())));
Expand All @@ -162,14 +160,10 @@ public void testLoggerWithMDCs() {
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())));
Expand All @@ -185,14 +179,10 @@ public void testLoggerWithMDCsAndException() {
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())));
Expand All @@ -207,14 +197,10 @@ public void testLoggerWithMDCValueIsNull() {
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())));
Expand All @@ -229,14 +215,10 @@ public void testLoggerWithExternalSystemCustomLogKey() {
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())));
Expand Down