Class LoggingUtils
- java.lang.Object
-
- org.apache.sshd.common.util.logging.LoggingUtils
-
public final class LoggingUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description privateLoggingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Consumer<T>debugClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>debugClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)static <T> java.util.function.Consumer<T>errorClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>errorClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)static java.util.NavigableMap<java.lang.Integer,java.lang.String>generateMnemonicMap(java.lang.Class<?> clazz, java.lang.String commonPrefix)Scans using reflection API for all fields that arepublic static finalthat start with the given common prefix (case sensitive) and are of typeNumber.static java.util.NavigableMap<java.lang.Integer,java.lang.String>generateMnemonicMap(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate.static java.util.Map<java.lang.String,java.lang.Integer>getAmbiguousMenmonics(java.lang.Class<?> clazz, java.lang.String commonPrefix)Scans using reflection API for all numericpublic static finalfields that have a common prefix and whose value is used by several of the other matching fieldsstatic java.util.Map<java.lang.String,java.lang.Integer>getAmbiguousMenmonics(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate and whose value is used by several of the other matching fieldsstatic java.util.Collection<java.lang.reflect.Field>getMnemonicFields(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate.static <T> java.util.function.Consumer<T>infoClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>infoClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)static booleanisLoggable(java.util.logging.Level level, java.util.logging.Level threshold)Verifies if the given level is above the required threshold for logging.static booleanisLoggable(org.slf4j.Logger logger, java.util.logging.Level level)static <T> java.util.function.Consumer<T>loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level)static <T> java.util.function.Consumer<T>loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Throwable t)static voidlogMessage(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)static <T> java.util.function.Consumer<T>nologClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>traceClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>traceClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)static <T> java.util.function.Consumer<T>warnClosure(org.slf4j.Logger logger)static <T> java.util.function.Consumer<T>warnClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)static SimplifiedLogwrap(org.slf4j.Logger logger)
-
-
-
Method Detail
-
generateMnemonicMap
public static java.util.NavigableMap<java.lang.Integer,java.lang.String> generateMnemonicMap(java.lang.Class<?> clazz, java.lang.String commonPrefix)Scans using reflection API for all fields that arepublic static finalthat start with the given common prefix (case sensitive) and are of typeNumber.- Parameters:
clazz- TheClassto querycommonPrefix- The expected common prefix- Returns:
- A
NavigableMapof all the matching fields, where key=the field'sIntegervalue and mapping=the field's name - See Also:
generateMnemonicMap(Class, Predicate)
-
generateMnemonicMap
public static java.util.NavigableMap<java.lang.Integer,java.lang.String> generateMnemonicMap(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate. Any field that is not such or fail to retrieve its value, or has a duplicate value is silently skipped.- Parameters:
clazz- TheClassto queryacceptor- ThePredicateused to decide whether to process theField(besides being aNumberandpublic static final).- Returns:
- A
NavigableMapof all the matching fields, where key=the field'sIntegervalue and mapping=the field's name - See Also:
getMnemonicFields(Class, Predicate)
-
getAmbiguousMenmonics
public static java.util.Map<java.lang.String,java.lang.Integer> getAmbiguousMenmonics(java.lang.Class<?> clazz, java.lang.String commonPrefix)Scans using reflection API for all numericpublic static finalfields that have a common prefix and whose value is used by several of the other matching fields- Parameters:
clazz- TheClassto querycommonPrefix- The expected common prefix- Returns:
- A
Mapof all the mnemonic fields names whose value is the same as other fields in this map. The key is the field's name and value is its associated opcode. - See Also:
getAmbiguousMenmonics(Class, Predicate)
-
getAmbiguousMenmonics
public static java.util.Map<java.lang.String,java.lang.Integer> getAmbiguousMenmonics(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate and whose value is used by several of the other matching fields- Parameters:
clazz- TheClassto queryacceptor- ThePredicateused to decide whether to process theField(besides being aNumberandpublic static final).- Returns:
- A
Mapof all the mnemonic fields names whose value is the same as other fields in this map. The key is the field's name and value is its associated opcode. - See Also:
getMnemonicFields(Class, Predicate)
-
getMnemonicFields
public static java.util.Collection<java.lang.reflect.Field> getMnemonicFields(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)Scans using reflection API for all numericpublic static finalfields that are also accepted by the predicate.- Parameters:
clazz- TheClassto queryacceptor- ThePredicateused to decide whether to process theField(besides being aNumberandpublic static final).- Returns:
- A
Collectionof all the fields that have satisfied all conditions
-
isLoggable
public static boolean isLoggable(java.util.logging.Level level, java.util.logging.Level threshold)Verifies if the given level is above the required threshold for logging.- Parameters:
level- TheLevelto evaluatethreshold- The thresholdLevel- Returns:
trueif the evaluated level is above the required threshold.Note(s):
If either argument is
nullthen result isfalse.If the evaluated level is
Level.OFFthen result isfalseregardless of the threshold.If the threshold is
Level.ALLand the evaluated level is notLevel.OFFthe result istrue.Otherwise, the evaluated level
Level.intValue()must be greater or equal to the threshold.
-
wrap
public static SimplifiedLog wrap(org.slf4j.Logger logger)
-
logMessage
public static void logMessage(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)
-
isLoggable
public static boolean isLoggable(org.slf4j.Logger logger, java.util.logging.Level level)- Parameters:
logger- TheLoggerinstance - ignored ifnulllevel- The validate logLevel- ignored ifnull- Returns:
trueif the level is enabled for the logger. The mapping of the level to the logger is as follows:Level.OFFalways returnsfalseLevel.SEVEREreturnsLogger.isErrorEnabled()Level.WARNINGreturnsLogger.isWarnEnabled()Level.INFOandLevel.ALLreturnsLogger.isInfoEnabled()Level.CONFIGandLevel.FINEreturnsLogger.isDebugEnabled()- All other levels return
Logger.isTraceEnabled()
-
loggingClosure
public static <T> java.util.function.Consumer<T> loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to uselevel- The logLevelmapped as follows:Level.OFF-nologClosure(Logger)Level.SEVERE-errorClosure(Logger)Level.WARNING-warnClosure(Logger)Level.INFO/Level.ALL-infoClosure(Logger)Level.CONFIG/Level.FINE-debugClosure(Logger)- All others -
traceClosure(Logger)
- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument if the specific level is enabled
-
loggingClosure
public static <T> java.util.function.Consumer<T> loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Throwable t)
-
nologClosure
public static <T> java.util.function.Consumer<T> nologClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs nothing when invoked
-
errorClosure
public static <T> java.util.function.Consumer<T> errorClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isErrorEnabled()
-
errorClosure
public static <T> java.util.function.Consumer<T> errorClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to usethrown- AThrowableto attach to the message - ignored ifnull- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isErrorEnabled()
-
warnClosure
public static <T> java.util.function.Consumer<T> warnClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isWarnEnabled()
-
warnClosure
public static <T> java.util.function.Consumer<T> warnClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to usethrown- AThrowableto attach to the message - ignored ifnull- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isWarnEnabled()
-
infoClosure
public static <T> java.util.function.Consumer<T> infoClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isInfoEnabled()
-
infoClosure
public static <T> java.util.function.Consumer<T> infoClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to usethrown- AThrowableto attach to the message - ignored ifnull- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isInfoEnabled()
-
debugClosure
public static <T> java.util.function.Consumer<T> debugClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isDebugEnabled()
-
debugClosure
public static <T> java.util.function.Consumer<T> debugClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to usethrown- AThrowableto attach to the message - ignored ifnull- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isDebugEnabled()
-
traceClosure
public static <T> java.util.function.Consumer<T> traceClosure(org.slf4j.Logger logger)
- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to use- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isTraceEnabled()
-
traceClosure
public static <T> java.util.function.Consumer<T> traceClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)- Type Parameters:
T- Generic message type consumer- Parameters:
logger- TheLoggerinstance to usethrown- AThrowableto attach to the message - ignored ifnull- Returns:
- A consumer whose
Consumer.accept(Object)method logs theString.valueOf(Object)value of its argument ifLogger.isTraceEnabled()
-
-