Repository: mina-sshd Updated Branches: refs/heads/master a4bb50233 -> f17bf3852
[SSHD-838] Remove LoggingUtils#logExceptionStackTrace Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/f17bf385 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/f17bf385 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/f17bf385 Branch: refs/heads/master Commit: f17bf3852e27b67f86fbd0d4091e788deb4202ba Parents: a4bb502 Author: Bryan Turner <[email protected]> Authored: Wed Aug 1 21:05:34 2018 +0300 Committer: Lyor Goldstein <[email protected]> Committed: Wed Aug 1 21:06:06 2018 +0300 ---------------------------------------------------------------------- .../sshd/common/io/nio2/Nio2Acceptor.java | 6 +- .../apache/sshd/common/io/nio2/Nio2Session.java | 6 +- .../sshd/common/util/logging/LoggingUtils.java | 114 ------------------- 3 files changed, 6 insertions(+), 120 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f17bf385/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java index 73a3c5f..1c63b54 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java @@ -31,14 +31,12 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; import org.apache.sshd.common.Closeable; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.io.IoAcceptor; import org.apache.sshd.common.io.IoHandler; import org.apache.sshd.common.util.ValidateUtils; -import org.apache.sshd.common.util.logging.LoggingUtils; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -289,7 +287,9 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor { log.warn("Caught {} while accepting incoming connection from {}: {}", exc.getClass().getSimpleName(), address, exc.getMessage()); - LoggingUtils.logExceptionStackTrace(log, Level.WARNING, exc); + if (log.isDebugEnabled()) { + log.debug("Incoming connection from " + address + " failure details", exc); + } return true; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f17bf385/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java index ec34404..9a9ef4a 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java @@ -32,7 +32,6 @@ import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.RuntimeSshException; @@ -44,7 +43,6 @@ import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.Readable; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.closeable.AbstractCloseable; -import org.apache.sshd.common.util.logging.LoggingUtils; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -255,7 +253,9 @@ public class Nio2Session extends AbstractCloseable implements IoSession { } catch (IOException e) { log.info("doCloseImmediately({}) {} caught while closing socket={}: {}", this, e.getClass().getSimpleName(), socket, e.getMessage()); - LoggingUtils.logExceptionStackTrace(log, Level.INFO, e); + if (debugEnabled) { + log.debug("doCloseImmediately(" + this + ") socket=" + socket + " close failure details", e); + } } service.sessionClosed(this); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f17bf385/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java index 7674471..8b3154a 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java @@ -19,7 +19,6 @@ package org.apache.sshd.common.util.logging; -import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -30,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.logging.Level; @@ -44,14 +42,6 @@ import org.slf4j.Logger; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public final class LoggingUtils { - /** - * Default value used for {@link #logExceptionStackTrace(Logger, Level, Throwable) logExceptionStackTrace} - * unless {@link #setDefaultStackTraceLoggingDepth(int) overridden} - */ - public static final int DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE = Byte.SIZE; - - private static final AtomicInteger DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE_HOLDER = - new AtomicInteger(DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE); private LoggingUtils() { throw new UnsupportedOperationException("No instance"); @@ -555,108 +545,4 @@ public final class LoggingUtils { } }; } - - /** - * Logs the stack trace of the exception up to {@link #getDefaultStackTraceLoggingDepth() default depth} - * or available stack trace elements. - * - * @param logger The {@link Logger} instance to log the information - * @param level The logging {@link Level} to use - * @param t The {@link Throwable} data to write - ignored if {@code null} - */ - public static void logExceptionStackTrace(Logger logger, Level level, Throwable t) { - logExceptionStackTrace(logger, level, t, getDefaultStackTraceLoggingDepth()); - } - - /** - * Logs the stack trace of the exception up to specified depth or available stack trace elements. - * - * @param logger The {@link Logger} instance to log the information - * @param level The logging {@link Level} to use - * @param t The {@link Throwable} data to write - ignored if {@code null} - * @param maxDepth Maximum stack trace elements to log - if non-positive then nothing is logged - */ - public static void logExceptionStackTrace(Logger logger, Level level, Throwable t, int maxDepth) { - if ((t == null) || (maxDepth <= 0) || (!isLoggable(logger, level))) { - return; - } - - Consumer<String> executor = loggingClosure(logger, level); - logExceptionStackTrace(t, maxDepth, executor); - } - - /** - * Logs the stack trace of the exception up to specified depth or available stack trace elements. - * - * @param t The {@link Throwable} data to write - ignored if {@code null} - * @param maxDepth Maximum stack trace elements to log - if non-positive then nothing is logged - * @param executor The {@link Consumer} invoked for each formatted stack trace element - */ - public static void logExceptionStackTrace(Throwable t, int maxDepth, Consumer<? super String> executor) { - if ((t == null) || (maxDepth <= 0) || (executor == null)) { - return; - } - StackTraceElement[] elements = t.getStackTrace(); - int numElements = GenericUtils.length(elements); - StringBuilder workBuf = new StringBuilder(Byte.MAX_VALUE); - for (int index = 0, maxElements = Math.min(maxDepth, numElements); index < maxElements; index++) { - StackTraceElement ste = elements[index]; - workBuf.setLength(0); // re-use - try { - appendStackTraceElement(workBuf.append(" at "), ste); - } catch (IOException e) { - throw new RuntimeException("Unexpected failure (" + e.getClass().getSimpleName() + ")" + " to append stack-trace-element=" + ste + ": " + e.getMessage(), e); - } - executor.accept(workBuf.toString()); - } - } - - /** - * @return The default value used by {@link #logExceptionStackTrace(Logger, Level, Throwable)} - */ - public static int getDefaultStackTraceLoggingDepth() { - return Math.max(DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE_HOLDER.get(), DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE); - } - - /** - * @param value The value to set - <B>Note:</B> the effective value is the <U>maximum</U> - * between it and {@value #DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE} - */ - public static void setDefaultStackTraceLoggingDepth(int value) { - DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE_HOLDER.set(Math.max(value, DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE)); - } - - /** - * Generates a result very similar to {@link StackTraceElement#toString()} - * - * @param <A> The {@link Appendable} target type - * @param sb The target appender - * @param ste The {@link StackTraceElement} to append - ignored if {@code null} - * @return The updated appender instance - * @throws IOException If failed to append the data - */ - public static <A extends Appendable> A appendStackTraceElement(A sb, StackTraceElement ste) throws IOException { - if (ste == null) { - return sb; - } - - sb.append(ste.getClassName()).append('.').append(ste.getMethodName()); - if (ste.isNativeMethod()) { - sb.append("(Native Method)"); - return sb; - } - - sb.append('('); - - String fileName = ste.getFileName(); - sb.append(GenericUtils.isEmpty(fileName) ? "Unknown Source" : fileName); - - int lineNumber = ste.getLineNumber(); - if (lineNumber >= 0) { - sb.append(':').append(Integer.toString(lineNumber)); - } - sb.append(')'); - - return sb; - } }
