Class LoggingExceptionCallback
- java.lang.Object
-
- com.helger.commons.callback.exception.LoggingExceptionCallback
-
- All Implemented Interfaces:
IExceptionCallback<Throwable>,ICallback,IHasErrorLevel,IErrorIndicator,ISuccessIndicator
@ThreadSafe public class LoggingExceptionCallback extends Object implements IExceptionCallback<Throwable>, IHasErrorLevel
A specific implementation of theIExceptionCallbackinterface, that logs all exceptions to a standard logger.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description LoggingExceptionCallback()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IErrorLevelgetErrorLevel()protected StringgetLogMessage(Throwable t)Get the text to be logged for a certain exceptionprotected booleanisLogException(Throwable t)Check if the passed exception should be part of the log entry.voidonException(Throwable t)Called when an exception of the specified type occurred.LoggingExceptionCallbacksetErrorLevel(IErrorLevel aErrorLevel)Set the error level to be used.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.error.level.IHasErrorLevel
hasErrorLevel, isError, isFailure, isNoError, isSuccess
-
Methods inherited from interface com.helger.commons.state.ISuccessIndicator
and, or
-
-
-
-
Method Detail
-
getErrorLevel
@Nonnull public IErrorLevel getErrorLevel()
- Specified by:
getErrorLevelin interfaceIHasErrorLevel- Returns:
- The configured error level. Never
null.
-
setErrorLevel
@Nonnull public final LoggingExceptionCallback setErrorLevel(@Nonnull IErrorLevel aErrorLevel)
Set the error level to be used.- Parameters:
aErrorLevel- Error level to use. May not benull.- Returns:
- this for chaining
-
getLogMessage
@Nonnull @Nonempty @OverrideOnDemand protected String getLogMessage(@Nullable Throwable t)
Get the text to be logged for a certain exception- Parameters:
t- The exception to be logged. May theoretically benull.- Returns:
- The text to be logged. May neither be
nullnor empty.
-
isLogException
@OverrideOnDemand protected boolean isLogException(@Nullable Throwable t)
Check if the passed exception should be part of the log entry.- Parameters:
t- The exception to check. May theoretically benull.- Returns:
trueto log the exception,falseto not log it
-
onException
public void onException(@Nullable Throwable t)
Description copied from interface:IExceptionCallbackCalled when an exception of the specified type occurred. You may not re-throw the exception from in here!- Specified by:
onExceptionin interfaceIExceptionCallback<Throwable>- Parameters:
t- The exception. Nevernull.
-
-