Class LoggerTools


  • public final class LoggerTools
    extends Object
    Provides commonly used functionality for logging.
    Author:
    Patrick Schmidt
    • 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 calling LoggerTools.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?
        These locations may of course also display a generic error dialogue if appropriate.
        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, a RuntimeException will be printed to System.err, while a VirtualMachineError will print the designated string to System.err. No complex logic should take place in case of a second VirtualMachineError. However, if this leads to another RuntimeException or VirtualMachineError, 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 second VirtualMachineError occurs while logging the designated error.