public final class LoggingUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE
Default value used for
logExceptionStackTrace
unless overridden |
private static java.util.concurrent.atomic.AtomicInteger |
DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE_HOLDER |
Modifier | Constructor and Description |
---|---|
private |
LoggingUtils() |
Modifier and Type | Method and Description |
---|---|
static <A extends java.lang.Appendable> |
appendStackTraceElement(A sb,
java.lang.StackTraceElement ste)
Generates a result very similar to
StackTraceElement.toString() |
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.Map<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 numeric
public static final fields
that are also accepted by the predicate. |
static java.util.Map<java.lang.Integer,java.lang.String> |
generateMnemonicMap(java.lang.Class<?> clazz,
java.lang.String commonPrefix)
Scans using reflection API for all fields that are
public static final
that start with the given common prefix (case sensitive) and are of type
Number . |
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 numeric
public static final fields
that are also accepted by the predicate and whose value is used by several of the other
matching fields |
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 numeric
public static final fields
that have a common prefix and whose value is used by several of the other
matching fields |
static int |
getDefaultStackTraceLoggingDepth() |
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 numeric
public static final fields
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 boolean |
isLoggable(java.util.logging.Level level,
java.util.logging.Level threshold)
Verifies if the given level is above the required threshold for logging.
|
static boolean |
isLoggable(org.slf4j.Logger logger,
java.util.logging.Level level) |
static void |
logExceptionStackTrace(org.slf4j.Logger logger,
java.util.logging.Level level,
java.lang.Throwable t)
Logs the stack trace of the exception up to
default depth
or available stack trace elements. |
static void |
logExceptionStackTrace(org.slf4j.Logger logger,
java.util.logging.Level level,
java.lang.Throwable t,
int maxDepth)
Logs the stack trace of the exception up to specified depth or available stack trace elements.
|
static void |
logExceptionStackTrace(java.lang.Throwable t,
int maxDepth,
java.util.function.Consumer<? super java.lang.String> executor)
Logs the stack trace of the exception up to specified depth or available stack trace elements.
|
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 void |
logMessage(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 void |
setDefaultStackTraceLoggingDepth(int value) |
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 SimplifiedLog |
wrap(org.slf4j.Logger logger) |
public static final int DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE
logExceptionStackTrace
unless overridden
private static final java.util.concurrent.atomic.AtomicInteger DEFAULT_STACK_TRACE_LOGGING_DEPTH_VALUE_HOLDER
public static java.util.Map<java.lang.Integer,java.lang.String> generateMnemonicMap(java.lang.Class<?> clazz, java.lang.String commonPrefix)
public static final
that start with the given common prefix (case sensitive) and are of type
Number
.clazz
- The Class
to querycommonPrefix
- The expected common prefixMap
of all the matching fields, where key=the field's Integer
value and mapping=the field's namegenerateMnemonicMap(Class, Predicate)
public static java.util.Map<java.lang.Integer,java.lang.String> generateMnemonicMap(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)
public static final
fields
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.clazz
- The Class
to queryacceptor
- The Predicate
used to decide whether to process the Field
(besides being a Number
and public static final
).Map
of all the matching fields, where key=the field's Integer
value and mapping=the field's namegetMnemonicFields(Class, Predicate)
public static java.util.Map<java.lang.String,java.lang.Integer> getAmbiguousMenmonics(java.lang.Class<?> clazz, java.lang.String commonPrefix)
public static final
fields
that have a common prefix and whose value is used by several of the other
matching fieldsclazz
- The Class
to querycommonPrefix
- The expected common prefixMap
of 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.getAmbiguousMenmonics(Class, Predicate)
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)
public static final
fields
that are also accepted by the predicate and whose value is used by several of the other
matching fieldsclazz
- The Class
to queryacceptor
- The Predicate
used to decide whether to process the Field
(besides being a Number
and public static final
).Map
of 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.getMnemonicFields(Class, Predicate)
public static java.util.Collection<java.lang.reflect.Field> getMnemonicFields(java.lang.Class<?> clazz, java.util.function.Predicate<? super java.lang.reflect.Field> acceptor)
public static final
fields
that are also accepted by the predicate.clazz
- The Class
to queryacceptor
- The Predicate
used to decide whether to process the Field
(besides being a Number
and public static final
).Collection
of all the fields that have satisfied all conditionspublic static boolean isLoggable(java.util.logging.Level level, java.util.logging.Level threshold)
level
- The Level
to evaluatethreshold
- The threshold Level
true
if the evaluated level is above the required
threshold.
Note(s):
If either argument is null
then result is false
.
If the evaluated level is Level.OFF
then result is false
regardless of the threshold.
If the threshold is Level.ALL
and the evaluated level is
not Level.OFF
the result is true
.
Otherwise, the evaluated level Level.intValue()
must be
greater or equal to the threshold.
public static SimplifiedLog wrap(org.slf4j.Logger logger)
public static void logMessage(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)
public static boolean isLoggable(org.slf4j.Logger logger, java.util.logging.Level level)
logger
- The Logger
instance - ignored if null
level
- The validate log Level
- ignored if null
true
if the level is enabled for the logger. The
mapping of the level to the logger is as follows:
Level.OFF
always returns false
Level.SEVERE
returns Logger.isErrorEnabled()
Level.WARNING
returns Logger.isWarnEnabled()
Level.INFO
and Level.ALL
returns Logger.isInfoEnabled()
Level.CONFIG
and Level.FINE
returns Logger.isDebugEnabled()
Logger.isTraceEnabled()
public static <T> java.util.function.Consumer<T> loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level)
T
- Generic message type consumerlogger
- The Logger
instance to uselevel
- The log Level
mapped 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)
traceClosure(Logger)
Consumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if the specific level is enabledpublic static <T> java.util.function.Consumer<T> loggingClosure(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Throwable t)
public static <T> java.util.function.Consumer<T> nologClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs nothing when invokedpublic static <T> java.util.function.Consumer<T> errorClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isErrorEnabled()
public static <T> java.util.function.Consumer<T> errorClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)
T
- Generic message type consumerlogger
- The Logger
instance to usethrown
- A Throwable
to attach to the message - ignored if null
Consumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isErrorEnabled()
public static <T> java.util.function.Consumer<T> warnClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isWarnEnabled()
public static <T> java.util.function.Consumer<T> warnClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)
T
- Generic message type consumerlogger
- The Logger
instance to usethrown
- A Throwable
to attach to the message - ignored if null
Consumer.accept(Object)
method logs the String.valueOf(Object)
value of its argument if Logger.isWarnEnabled()
public static <T> java.util.function.Consumer<T> infoClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs the String.valueOf(Object)
value of its argument if Logger.isInfoEnabled()
public static <T> java.util.function.Consumer<T> infoClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)
T
- Generic message type consumerlogger
- The Logger
instance to usethrown
- A Throwable
to attach to the message - ignored if null
Consumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isInfoEnabled()
public static <T> java.util.function.Consumer<T> debugClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isDebugEnabled()
public static <T> java.util.function.Consumer<T> debugClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)
T
- Generic message type consumerlogger
- The Logger
instance to usethrown
- A Throwable
to attach to the message - ignored if null
Consumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isDebugEnabled()
public static <T> java.util.function.Consumer<T> traceClosure(org.slf4j.Logger logger)
T
- Generic message type consumerlogger
- The Logger
instance to useConsumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isTraceEnabled()
public static <T> java.util.function.Consumer<T> traceClosure(org.slf4j.Logger logger, java.lang.Throwable thrown)
T
- Generic message type consumerlogger
- The Logger
instance to usethrown
- A Throwable
to attach to the message - ignored if null
Consumer.accept(Object)
method logs the
String.valueOf(Object)
value of its argument if Logger.isTraceEnabled()
public static void logExceptionStackTrace(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Throwable t)
default depth
or available stack trace elements.logger
- The Logger
instance to log the informationlevel
- The logging Level
to uset
- The Throwable
data to write - ignored if null
public static void logExceptionStackTrace(org.slf4j.Logger logger, java.util.logging.Level level, java.lang.Throwable t, int maxDepth)
logger
- The Logger
instance to log the informationlevel
- The logging Level
to uset
- The Throwable
data to write - ignored if null
maxDepth
- Maximum stack trace elements to log - if non-positive then nothing is loggedpublic static void logExceptionStackTrace(java.lang.Throwable t, int maxDepth, java.util.function.Consumer<? super java.lang.String> executor)
t
- The Throwable
data to write - ignored if null
maxDepth
- Maximum stack trace elements to log - if non-positive then nothing is loggedexecutor
- The Consumer
invoked for each formatted stack trace elementpublic static int getDefaultStackTraceLoggingDepth()
logExceptionStackTrace(Logger, Level, Throwable)
public static void setDefaultStackTraceLoggingDepth(int value)
value
- The value to set - Note: the effective value is the maximum
between it and 8public static <A extends java.lang.Appendable> A appendStackTraceElement(A sb, java.lang.StackTraceElement ste) throws java.io.IOException
StackTraceElement.toString()
A
- The Appendable
target typesb
- The target appenderste
- The StackTraceElement
to append - ignored if null
java.io.IOException
- If failed to append the data