Class AttivioLogger

  • All Implemented Interfaces:
    StatusListener

    public class AttivioLogger
    extends java.lang.Object
    implements StatusListener
    Unifies all logging facilities through SLF4j with special handling for various features such as error codes and log message formatting.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AttivioLogger​(java.lang.String name)
      Creates the underlying logger.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void debug​(java.lang.String msg, java.lang.Object... params)
      Logs a debug message.
      void debug​(java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)
      Logs a debug message with an exception.
      void entering​(java.lang.String sourceClass, java.lang.String sourceMethod)
      Logs an entering message at trace level.
      void entering​(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object... params)
      Logs an entering message at trace level.
      void error​(AttivioException ae)
      Log an AttivioException at an error level
      void error​(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)
      Logs a error message with an error code.
      void error​(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)
      Logs a severe message with an error code.
      void exiting​(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)
      Logs an entering message at trace level.
      static java.lang.String formatLogMessage​(java.lang.String msg, java.lang.Object... params)
      Safely formats a log message handling null input as well as returning a warning message if message formatting failed.
      static AttivioLogger.ThreadLocalComponentName getComponentNameHandle()  
      static int getErrorCount()  
      java.lang.Object getLoggedObject()
      Gets the specific object being logged.
      static AttivioLogger getLogger​(java.lang.Class<?> c)
      Gets a logger by class.
      static AttivioLogger getLogger​(java.lang.Object o)
      Gets a logger by object's class.
      static AttivioLogger getLogger​(java.lang.String name)
      Gets a logger by name.
      long getMaxMessageLength()
      Gets the maximum message length.
      static int getWarningCount()  
      void ignoreException​(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)
      Notes that an exception is being ignored at debug level.
      void ignoreException​(java.lang.Throwable t)
      Notes that an exception is being ignored.
      void ignoreException​(java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)
      Notes that an exception is being ignored.
      void info​(java.lang.String msg, java.lang.Object... params)
      Logs an info message.
      boolean isAppendComponentName()  
      boolean isDebugEnabled()
      Tells whether the DEBUG level is set
      boolean isInfoEnabled()
      Tells whether the INFO level is set
      boolean isTraceEnabled()
      Tells whether the TRACE level is set
      protected java.lang.String prepareMessage​(java.lang.String original, java.lang.Object... params)
      Formats varargs
      void setAppendComponentName​(boolean appendComponentName)  
      void setLoggedObject​(java.lang.Object loggedObject)
      Sets the object being logged.
      void setMaxMessageLength​(long maxMessageLength)
      Sets the maximum string length for log messages.
      void trace​(java.lang.String msg, java.lang.Object... params)
      Logs a trace message.
      void warn​(AttivioException ae)
      Log an AttivioException at a warning level.
      void warn​(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)
      Logs a warning message with an error code.
      void warn​(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)
      Logs a warning message without an error code.
      • Methods inherited from class java.lang.Object

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

      • AttivioLogger

        protected AttivioLogger​(java.lang.String name)
        Creates the underlying logger.
        Parameters:
        name - name for logger
    • Method Detail

      • getLogger

        public static final AttivioLogger getLogger​(java.lang.String name)
        Gets a logger by name.
        Parameters:
        name - name for logger
        Returns:
        the logger for this name
      • getLogger

        public static final AttivioLogger getLogger​(java.lang.Class<?> c)
        Gets a logger by class.
        Parameters:
        c - the class to use for naming conventions
        Returns:
        the logger for this class/name
      • getLogger

        public static final AttivioLogger getLogger​(java.lang.Object o)
        Gets a logger by object's class. The object used to create the logger becomes the loggedObject (see getLoggedObject().
        Parameters:
        o - the object whose class to use for naming conventions
        Returns:
        the logger for this class/name
      • trace

        public void trace​(java.lang.String msg,
                          java.lang.Object... params)
        Logs a trace message.
        Parameters:
        msg - Message to log
        params - variable arguments for the format string
        See Also:
        debug(String, Object...)
      • debug

        public void debug​(java.lang.String msg,
                          java.lang.Object... params)
        Logs a debug message.
        Specified by:
        debug in interface StatusListener
        Parameters:
        msg - Message to log
        params - variable arguments for the format string
      • debug

        public void debug​(java.lang.Throwable t,
                          java.lang.String msg,
                          java.lang.Object... params)
        Logs a debug message with an exception.
        Parameters:
        msg - Message to log
        params - variable arguments for the format string
      • ignoreException

        public void ignoreException​(java.lang.Throwable t)
        Notes that an exception is being ignored.
        Parameters:
        t - the exception being ignored
      • ignoreException

        public void ignoreException​(java.lang.Throwable t,
                                    java.lang.String msg,
                                    java.lang.Object... args)
        Notes that an exception is being ignored.
        Parameters:
        t - the exception being ignored
        msg - additional message about why this exception is being ignored.
      • ignoreException

        public void ignoreException​(ErrorCode logMessageType,
                                    java.lang.Throwable t,
                                    java.lang.String msg,
                                    java.lang.Object... args)
        Notes that an exception is being ignored at debug level.
        Parameters:
        logMessageType -
        t - the exception being ignored
        msg - additional message about why this exception is being ignored.
      • info

        public void info​(java.lang.String msg,
                         java.lang.Object... params)
        Logs an info message.
        Specified by:
        info in interface StatusListener
        Parameters:
        msg - message to log
        params - variable arguments for the format string
      • warn

        public void warn​(ErrorCode logMessageType,
                         java.lang.Throwable t,
                         java.lang.String msg,
                         java.lang.Object... params)
        Logs a warning message without an error code.
        Specified by:
        warn in interface StatusListener
        Parameters:
        logMessageType -
        msg - Message to log
        params - variable arguments for the format string
      • warn

        public void warn​(ErrorCode logMessageType,
                         java.lang.String msg,
                         java.lang.Object... params)
        Logs a warning message with an error code.
        Specified by:
        warn in interface StatusListener
        Parameters:
        logMessageType -
        msg - Message to log
        params - variable arguments for the format string
      • warn

        public void warn​(AttivioException ae)
        Log an AttivioException at a warning level.
        Specified by:
        warn in interface StatusListener
        Parameters:
        ae - the AttivioException
      • error

        public void error​(AttivioException ae)
        Log an AttivioException at an error level
        Parameters:
        ae - The AttivioException
      • error

        public void error​(ErrorCode logMessageType,
                          java.lang.String msg,
                          java.lang.Object... params)
        Logs a error message with an error code.
        Parameters:
        logMessageType -
        msg - Message to log
        params - variable arguments for the format string
      • error

        public void error​(ErrorCode logMessageType,
                          java.lang.Throwable t,
                          java.lang.String msg,
                          java.lang.Object... params)
        Logs a severe message with an error code.
        Specified by:
        error in interface StatusListener
        Parameters:
        logMessageType -
        t - Throwable to log
        msg - Message to log
        params - variable arguments for the format string
      • entering

        public void entering​(java.lang.String sourceClass,
                             java.lang.String sourceMethod)
        Logs an entering message at trace level.
        Parameters:
        sourceClass - class name
        sourceMethod - method name
      • entering

        public void entering​(java.lang.String sourceClass,
                             java.lang.String sourceMethod,
                             java.lang.Object... params)
        Logs an entering message at trace level.
        Parameters:
        sourceClass - class name
        sourceMethod - method name
        params - method params
      • exiting

        public void exiting​(java.lang.String sourceClass,
                            java.lang.String sourceMethod,
                            java.lang.Object result)
        Logs an entering message at trace level.
        Parameters:
        sourceClass - class name
        sourceMethod - method name
        result - method result
      • prepareMessage

        protected java.lang.String prepareMessage​(java.lang.String original,
                                                  java.lang.Object... params)
        Formats varargs
        Parameters:
        original - The original message being logged
        params - string format arguments
        Returns:
        The formatted version of the message
      • getMaxMessageLength

        public long getMaxMessageLength()
        Gets the maximum message length.
        Returns:
        maxMessageLength. Log messages longer than this length will be truncated.
      • setMaxMessageLength

        public void setMaxMessageLength​(long maxMessageLength)
        Sets the maximum string length for log messages. Log messages longer than this length will be truncated. The minimum value for this parameter is 3.
        Parameters:
        maxMessageLength - the maximum message length
      • getLoggedObject

        public java.lang.Object getLoggedObject()
        Gets the specific object being logged. Will have a value if the logger was created via getLogger(Object). If non-null, then the object id will appear in the log message. Allows for teasing apart log messages from multiple instances of a class.
        Returns:
        the specific object being logged.
      • setLoggedObject

        public void setLoggedObject​(java.lang.Object loggedObject)
        Sets the object being logged. See getLoggedObject().
        Parameters:
        loggedObject - the logged object
      • isTraceEnabled

        public boolean isTraceEnabled()
        Tells whether the TRACE level is set
        Returns:
        true if TRACE level is set
      • isInfoEnabled

        public boolean isInfoEnabled()
        Tells whether the INFO level is set
        Returns:
        true if INFO level is set
      • isDebugEnabled

        public boolean isDebugEnabled()
        Tells whether the DEBUG level is set
        Returns:
        true if DEBUG level is set
      • isAppendComponentName

        public boolean isAppendComponentName()
      • setAppendComponentName

        public void setAppendComponentName​(boolean appendComponentName)
      • getErrorCount

        public static int getErrorCount()
        Returns:
        the number of errors that have been created since system startup.
      • getWarningCount

        public static int getWarningCount()
        Returns:
        the number of warnings that have been created since system startup.
      • formatLogMessage

        public static final java.lang.String formatLogMessage​(java.lang.String msg,
                                                              java.lang.Object... params)
        Safely formats a log message handling null input as well as returning a warning message if message formatting failed.

        In the event of a message format failure also log a message to the AttivioLogger's class logger at the warning level to indicate an problem. This means that this method shoudl not be called until after Attivio properties have been read and the underlying logging system ahs been setup correctly.