Package org.javacord.api.util.logging
Class ExceptionLogger
- java.lang.Object
-
- org.javacord.api.util.logging.ExceptionLogger
-
public class ExceptionLogger extends java.lang.ObjectThis class contains some helpers to log exceptions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Function<java.lang.Throwable,T>get(java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a function that can be used in theCompletableFuture.exceptionally(Function)method.static <T> java.util.function.Function<java.lang.Throwable,T>get(java.util.function.Predicate<java.lang.Throwable> logFilter, java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a function that can be used in theCompletableFuture.exceptionally(Function)method.static java.util.function.Consumer<java.lang.Throwable>getConsumer(java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a consumer that can for example be used in theTextChannel.typeContinuously(Consumer)method.static java.util.function.Consumer<java.lang.Throwable>getConsumer(java.util.function.Predicate<java.lang.Throwable> logFilter, java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a consumer that can for example be used in theTextChannel.typeContinuously(Consumer)method.static java.lang.Thread.UncaughtExceptionHandlergetUncaughtExceptionHandler()Returns an uncaught exception handler that can be used in theThread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)andThread.setUncaughtExceptionHandler(UncaughtExceptionHandler)methods.static java.lang.ThrowableunwrapThrowable(java.lang.Throwable throwable)UnwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsand returns the actual cause, or the given argument itself if it is not one of the listed exceptions types.
-
-
-
Method Detail
-
getConsumer
@SafeVarargs public static java.util.function.Consumer<java.lang.Throwable> getConsumer(java.util.function.Predicate<java.lang.Throwable> logFilter, java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a consumer that can for example be used in theTextChannel.typeContinuously(Consumer)method. It unwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsfirst, and then adds a freshCompletionExceptionas wrapper with the stacktrace of the caller of this method and logs it afterwards. The rewrapped exception is only logged if the givenlogFilterpredicate allows the exception and the class of it is not in theignoredThrowableTypes.- Parameters:
logFilter- The predicate the unwrapped exception is tested against.ignoredThrowableTypes- The throwable types that should never be logged.- Returns:
- A consumer which logs the given throwable.
-
getConsumer
@SafeVarargs public static java.util.function.Consumer<java.lang.Throwable> getConsumer(java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)
Returns a consumer that can for example be used in theTextChannel.typeContinuously(Consumer)method. It unwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsfirst, and then adds a freshCompletionExceptionas wrapper with the stacktrace of the caller of this method and logs it afterwards. The rewrapped exception is only logged if it is not in theignoredThrowableTypes.- Parameters:
ignoredThrowableTypes- The throwable types that should never be logged.- Returns:
- A consumer which logs the given throwable.
-
get
@SafeVarargs public static <T> java.util.function.Function<java.lang.Throwable,T> get(java.util.function.Predicate<java.lang.Throwable> logFilter, java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)Returns a function that can be used in theCompletableFuture.exceptionally(Function)method. It unwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsfirst, and then adds a freshCompletionExceptionas wrapper with the stacktrace of the caller of this method and logs it afterwards. The rewrapped exception is only logged if the givenlogFilterpredicate allows the exception and the class of it is not in theignoredThrowableTypes.- Type Parameters:
T- The return type of the function.- Parameters:
logFilter- The predicate the unwrapped exception is tested against.ignoredThrowableTypes- The throwable types that should never be logged.- Returns:
- A function which logs the given throwable and returns
null.
-
get
@SafeVarargs public static <T> java.util.function.Function<java.lang.Throwable,T> get(java.lang.Class<? extends java.lang.Throwable>... ignoredThrowableTypes)
Returns a function that can be used in theCompletableFuture.exceptionally(Function)method. It unwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsfirst, and then adds a freshCompletionExceptionas wrapper with the stacktrace of the caller of this method and logs it afterwards. The rewrapped exception is only logged if it is not in theignoredThrowableTypes.- Type Parameters:
T- The return type of the function.- Parameters:
ignoredThrowableTypes- The throwable types that should never be logged.- Returns:
- A function which logs the given throwable and returns
null.
-
getUncaughtExceptionHandler
public static java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
Returns an uncaught exception handler that can be used in theThread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)andThread.setUncaughtExceptionHandler(UncaughtExceptionHandler)methods. It unwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsfirst and logs it afterwards, including the thread name.- Returns:
- An
Thread.UncaughtExceptionHandlerwhich logs the given throwable.
-
unwrapThrowable
public static java.lang.Throwable unwrapThrowable(java.lang.Throwable throwable)
UnwrapsCompletionExceptions,InvocationTargetExceptionsandExecutionExceptionsand returns the actual cause, or the given argument itself if it is not one of the listed exceptions types. If the bottom-most exception to unwrap does not have a cause, it is returned itself instead.- Parameters:
throwable- The throwable to unwrap.- Returns:
- The unwrapped throwable.
-
-