Package discord4j.common
Class LogUtil
- java.lang.Object
-
- discord4j.common.LogUtil
-
public class LogUtil extends Object
Utility to support logging details.
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_BUCKET_IDstatic StringKEY_GATEWAY_IDstatic StringKEY_GUILD_IDstatic StringKEY_REQUEST_IDstatic StringKEY_SHARD_ID
-
Constructor Summary
Constructors Constructor Description LogUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Function<Context,Context>clearContext()static Stringformat(ContextView context, String msg)Format a message by unwrapping certainContextViewvalues as metadata, and if they exist, prepend them to the given message.static StringformatValue(Object value, int maxLength)static voidtraceDebug(Logger logger, Function<Boolean,String> messageFactory)Log a message depending on the enabled level for a givenLogger.
-
-
-
Field Detail
-
KEY_BUCKET_ID
public static final String KEY_BUCKET_ID
- See Also:
- Constant Field Values
-
KEY_REQUEST_ID
public static final String KEY_REQUEST_ID
- See Also:
- Constant Field Values
-
KEY_GATEWAY_ID
public static final String KEY_GATEWAY_ID
- See Also:
- Constant Field Values
-
KEY_SHARD_ID
public static final String KEY_SHARD_ID
- See Also:
- Constant Field Values
-
KEY_GUILD_ID
public static final String KEY_GUILD_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
format
public static String format(ContextView context, String msg)
Format a message by unwrapping certainContextViewvalues as metadata, and if they exist, prepend them to the given message.- Parameters:
context- a Reactor context to enrich the logging messagemsg- the logging message- Returns:
- a formatted log message
-
formatValue
public static String formatValue(@Nullable Object value, int maxLength)
- Parameters:
value- the value to formatmaxLength- maximum length of the formatted value if positive or impose no limit otherwise.- Returns:
- a formatted value
-
traceDebug
public static void traceDebug(Logger logger, Function<Boolean,String> messageFactory)
Log a message depending on the enabled level for a givenLogger. The supplied message factory will be applied withtrueif the logger has trace level enabled, given byLogger.isTraceEnabled(), ofalseotherwise.- Parameters:
logger- the logger instance used for logging a messagemessageFactory- aFunctionthat takestruevalue if the given logger has trace level enabled,falseotherwise, and produces a message to log.
-
-