Class Logger


  • public class Logger
    extends java.lang.Object
    Logs events in different levels.
    Author:
    Ilja Pavkovic
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AWT
      AWT messages are printed for debugging awt purposes
      static int DEBUG
      Debug messages are printed for debugging purposes
      static int ERROR
      Error messages are printed if an error occurs but the application can continue
      static int FATAL
      Fatal messages are messages which are printed before a fatal program exit
      static int FINE
      Fine messages are more fine grained than INFO messages, but not yet DEBUG
      static int FINER
      Fine messages are more fine grained than INFO messages, but not yet DEBUG
      static int FINEST
      Fine messages are more fine grained than INFO messages, but not yet DEBUG
      static int INFO
      Info messages are printed for informational purposes
      static int MAX_LEVEL  
      static int OFF
      This log level entirely stops all logging
      static int WARN
      Warning messages are info messages with warning character
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void activateDefaultLogListener​(boolean activate)
      Activates or de-activates the default listener, which logs to System.err.
      static void addLogListener​(LogListener l)
      Adds a listener to the list of notified listeners.
      void awt​(java.lang.Object aObj)
      Logs an AWT level message.
      void awt​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs an AWT level message.
      void clearError​(java.lang.Object aObj)
      Stops remembering an object for errorOnce(Object).
      void debug​(java.lang.Object aObj)
      Logs a message at the DEBUG level.
      void debug​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the DEBUG level.
      void error​(java.lang.Object aObj)
      Logs a message at the ERROR level.
      void error​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the ERROR level.
      void errorOnce​(java.lang.Object aObj)
      Logs a message at the ERROR level, but only if no equal message has been logged before.
      void fatal​(java.lang.Object aObj)
      Logs a message at the FATAL level.
      void fatal​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the FATAL level.
      void fine​(java.lang.Object aObj)
      Logs a message at the FINE level.
      void fine​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the FINE level.
      void finer​(java.lang.Object aObj)
      Logs a message at the FINER level.
      void finer​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the FINER level.
      void finest​(java.lang.Object aObj)
      Logs a message at the FINEST level.
      void finest​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the FINEST level.
      static Logger getInstance​(java.lang.Class<?> aClass)
      Returns a logger "personalized" for some class.
      static Logger getInstance​(java.lang.String aBase)
      Returns a logger with a specified name.
      static int getLevel()  
      static java.lang.String getLevel​(int level)  
      void info​(java.lang.Object aObj)
      Logs a message at the INFO level.
      void info​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the INFO level.
      boolean isAwtEnabled()  
      boolean isDebugEnabled()
      Returns true if the level is at least DEBUG.
      boolean isErrorEnabled()
      Returns true if log level is at least ERROR.
      boolean isFatalEnabled()
      Returns true if the log level is at least FATAL.
      boolean isFineEnabled()
      Returns true if the level is at least FINE.
      boolean isInfoEnabled()
      Returns true if level is at least INFO.
      boolean isWarnEnabled()
      Returns true if log level is at least WARN.
      void log​(int aLevel, java.lang.Object aObj, java.lang.Throwable aThrowable)  
      static void removeLogListener​(LogListener l)
      Removes l from the list of notified listeners.
      static void setLevel​(int level)
      Set the logging level.
      static void setLevel​(java.lang.String aLevel)  
      void warn​(java.lang.Object aObj)
      Logs a message at the WARN level.
      void warn​(java.lang.Object aObj, java.lang.Throwable aThrowable)
      Logs a message at the WARN level.
      void warnOnce​(java.lang.Object aObj)
      Logs a message at the WARN level, but only if no equals event has been logged before.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OFF

        public static final int OFF
        This log level entirely stops all logging
        See Also:
        Constant Field Values
      • FATAL

        public static final int FATAL
        Fatal messages are messages which are printed before a fatal program exit
        See Also:
        Constant Field Values
      • ERROR

        public static final int ERROR
        Error messages are printed if an error occurs but the application can continue
        See Also:
        Constant Field Values
      • WARN

        public static final int WARN
        Warning messages are info messages with warning character
        See Also:
        Constant Field Values
      • INFO

        public static final int INFO
        Info messages are printed for informational purposes
        See Also:
        Constant Field Values
      • FINE

        public static final int FINE
        Fine messages are more fine grained than INFO messages, but not yet DEBUG
        See Also:
        Constant Field Values
      • FINER

        public static final int FINER
        Fine messages are more fine grained than INFO messages, but not yet DEBUG
        See Also:
        Constant Field Values
      • FINEST

        public static final int FINEST
        Fine messages are more fine grained than INFO messages, but not yet DEBUG
        See Also:
        Constant Field Values
      • DEBUG

        public static final int DEBUG
        Debug messages are printed for debugging purposes
        See Also:
        Constant Field Values
      • AWT

        public static final int AWT
        AWT messages are printed for debugging awt purposes
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static Logger getInstance​(java.lang.Class<?> aClass)
        Returns a logger "personalized" for some class.
      • getInstance

        public static Logger getInstance​(java.lang.String aBase)
        Returns a logger with a specified name.
      • setLevel

        public static void setLevel​(int level)
        Set the logging level. Currently supported levels are FATAL, ERROR, WARN, INFO, FINE, DEBUG, AWT.
        Parameters:
        level - The new log level.
      • setLevel

        public static void setLevel​(java.lang.String aLevel)
      • getLevel

        public static int getLevel()
        Returns:
        The current verbosity level
      • getLevel

        public static java.lang.String getLevel​(int level)
        Returns:
        The string representation of level
      • log

        public void log​(int aLevel,
                        java.lang.Object aObj,
                        java.lang.Throwable aThrowable)
      • activateDefaultLogListener

        public static void activateDefaultLogListener​(boolean activate)
        Activates or de-activates the default listener, which logs to System.err.
      • fatal

        public void fatal​(java.lang.Object aObj)
        Logs a message at the FATAL level.
      • fatal

        public void fatal​(java.lang.Object aObj,
                          java.lang.Throwable aThrowable)
        Logs a message at the FATAL level.
      • isFatalEnabled

        public boolean isFatalEnabled()
        Returns true if the log level is at least FATAL.
      • error

        public void error​(java.lang.Object aObj)
        Logs a message at the ERROR level.
      • errorOnce

        public void errorOnce​(java.lang.Object aObj)
        Logs a message at the ERROR level, but only if no equal message has been logged before.
      • clearError

        public void clearError​(java.lang.Object aObj)
        Stops remembering an object for errorOnce(Object).
      • error

        public void error​(java.lang.Object aObj,
                          java.lang.Throwable aThrowable)
        Logs a message at the ERROR level.
      • isErrorEnabled

        public boolean isErrorEnabled()
        Returns true if log level is at least ERROR.
      • warn

        public void warn​(java.lang.Object aObj)
        Logs a message at the WARN level.
      • warnOnce

        public void warnOnce​(java.lang.Object aObj)
        Logs a message at the WARN level, but only if no equals event has been logged before.
      • warn

        public void warn​(java.lang.Object aObj,
                         java.lang.Throwable aThrowable)
        Logs a message at the WARN level.
      • isWarnEnabled

        public boolean isWarnEnabled()
        Returns true if log level is at least WARN.
      • info

        public void info​(java.lang.Object aObj)
        Logs a message at the INFO level.
      • info

        public void info​(java.lang.Object aObj,
                         java.lang.Throwable aThrowable)
        Logs a message at the INFO level.
      • isInfoEnabled

        public boolean isInfoEnabled()
        Returns true if level is at least INFO.
      • fine

        public void fine​(java.lang.Object aObj)
        Logs a message at the FINE level.
      • fine

        public void fine​(java.lang.Object aObj,
                         java.lang.Throwable aThrowable)
        Logs a message at the FINE level.
      • finer

        public void finer​(java.lang.Object aObj)
        Logs a message at the FINER level.
      • finer

        public void finer​(java.lang.Object aObj,
                          java.lang.Throwable aThrowable)
        Logs a message at the FINER level.
      • finest

        public void finest​(java.lang.Object aObj)
        Logs a message at the FINEST level.
      • finest

        public void finest​(java.lang.Object aObj,
                           java.lang.Throwable aThrowable)
        Logs a message at the FINEST level.
      • isFineEnabled

        public boolean isFineEnabled()
        Returns true if the level is at least FINE.
      • debug

        public void debug​(java.lang.Object aObj)
        Logs a message at the DEBUG level.
      • debug

        public void debug​(java.lang.Object aObj,
                          java.lang.Throwable aThrowable)
        Logs a message at the DEBUG level.
      • isDebugEnabled

        public boolean isDebugEnabled()
        Returns true if the level is at least DEBUG.
      • awt

        public void awt​(java.lang.Object aObj)
        Logs an AWT level message.
      • awt

        public void awt​(java.lang.Object aObj,
                        java.lang.Throwable aThrowable)
        Logs an AWT level message.
      • isAwtEnabled

        public boolean isAwtEnabled()
      • addLogListener

        public static void addLogListener​(LogListener l)
        Adds a listener to the list of notified listeners.
      • removeLogListener

        public static void removeLogListener​(LogListener l)
        Removes l from the list of notified listeners.