Package de.aristaflow.adept2.util
Class LoggerTools
- java.lang.Object
-
- de.aristaflow.adept2.util.LoggerTools
-
public final class LoggerTools extends Object
Provides commonly used functionality for logging.- Author:
- Patrick Schmidt
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Logger
getLogger(Class<?> cls)
Returns the appropriate logger for the given class.static Logger
getLogger(Object object)
Returns the appropriate logger for the given object.static String
getLoggerName(Class<?> cls)
Gets the name of the designated class for retrieving an appropriate logger.static void
logUnhandledException(Throwable exception)
Logs the given otherwise unhandled exception.static void
logVirtualMachineErrorSafely(VirtualMachineError vme, String backupMsg)
Logs the designated virtual machine error safely that is the error is logged as unhandled exception but problems occurring when logging are handled and swallowed if appropriate.
-
-
-
Method Detail
-
getLoggerName
public static String getLoggerName(Class<?> cls)
Gets the name of the designated class for retrieving an appropriate logger.- Parameters:
cls
- The name of the class for which to get a logger name.- Returns:
- The appropriate logger name for the designated class.
-
getLogger
public static Logger getLogger(Class<?> cls)
Returns the appropriate logger for the given class.getLoggerName(Class)
is used to determine the name of the logger.- Parameters:
cls
- the class for which to get the appropriate logger- Returns:
- the appropriate logger for the given class
-
getLogger
public static Logger getLogger(Object object)
Returns the appropriate logger for the given object. Calling this method is equivalent to callingLoggerTools.getLogger(object.getClass())
.- Parameters:
object
- the object for which to get the appropriate logger- Returns:
- the appropriate logger for the given object
-
logUnhandledException
public static void logUnhandledException(Throwable exception)
Logs the given otherwise unhandled exception. The purpose of this method is to prevent that exceptions go unnoticed (i.e. get swallowed completely or are logged to the Eclipse-specific log instead of appearing in our log. Places where this method should be called are e.g.WorkbenchAdvisor.eventLoopException(Throwable)
of Eclipse RCP applications- TODO: where else?
- Parameters:
exception
- the unhandled exception (Throwable
) to be logged
-
logVirtualMachineErrorSafely
public static void logVirtualMachineErrorSafely(VirtualMachineError vme, String backupMsg)
Logs the designated virtual machine error safely that is the error is logged as unhandled exception but problems occurring when logging are handled and swallowed if appropriate.
Before swallowing, aRuntimeException
will be printed toSystem.err
, while aVirtualMachineError
will print the designated string toSystem.err
. No complex logic should take place in case of a secondVirtualMachineError
. However, if this leads to anotherRuntimeException
orVirtualMachineError
, this will be swallowed to prevent the calling thread from dying.- Parameters:
vme
- A virtual machine error to be safely logged, that is the calling thread must survive under all circumstances.backupMsg
- The message to be used in case a secondVirtualMachineError
occurs while logging the designated error.
-
-