Class LogManager

  • Direct Known Subclasses:
    Default, Log4j

    public abstract class LogManager
    extends java.lang.Object
    The logging class that to log messages at different levels. Currently the following levels are supported.

    Eventually, each of the level can have a different writer stream underneath.

    The messages can be logged at various levels. The various levels of logging with increasing levels of verbosity are displayed in the following table.

    Logging LevelDescription
    FATAL all fatal error messages are logged in this level.
    ERROR all non fatal error messages are logged in this level.
    WARNING all warning messages are logged in this level.
    INFO all information logging messages are logged in this level.
    CONFIG all configuration messages are logged in this level.
    DEBUG all debug messages are logged in this level.
    Version:
    $Revision$
    Author:
    Karan Vahi, Gaurang Mehta
    • Constructor Summary

      Constructors 
      Constructor Description
      LogManager()
      The constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      LogManager add​(java.lang.String value)
      Add to the internal log buffer message a value with the default key.
      LogManager add​(java.lang.String key, java.lang.String value)
      Add to the internal log buffer message a value with the key oassed The buffer is logged later when the log() method is called.
      static LogManager getInstance​(java.lang.String logger, java.lang.String formatter)
      To get a reference to the the object.
      abstract int getLevel()
      Returns the debug level.
      abstract void initialize​(LogFormatter formatter, java.util.Properties properties)
      Sets the log formatter to use for formatting the messages.
      void log​(int level)
      Log the message represented by the internal log buffer.
      void log​(java.lang.String message, int level)
      Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.
      abstract void log​(java.lang.String message, java.lang.Exception e, int level)
      Logs the exception on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.
      protected abstract void logAlreadyFormattedMessage​(java.lang.String message, int level)
      A stop gap function .
      void logAndReset​(int level)
      Creates a log message with the contents of the internal log buffer.
      void logEntityHierarchyMessage​(java.lang.String parentType, java.lang.String parentID, java.lang.String childIDType, java.util.Collection<java.lang.String> childIDs)
      Log a message that connects the parent entities with the children.
      void logEntityHierarchyMessage​(java.lang.String parentType, java.lang.String parentID, java.lang.String childIDType, java.util.Collection<java.lang.String> childIDs, int level)
      Log a message that connects the parent entities with the children.
      void logEventCompletion()
      Logs the completion message on the basis of the debug level.
      abstract void logEventCompletion​(int level)
      Logs the completion message on the basis of the debug level.
      void logEventStart​(java.lang.String name, java.lang.String entityName, java.lang.String entityID)
      Log an event start message to INFO level
      void logEventStart​(java.lang.String name, java.lang.String entityName, java.lang.String entityID, int level)
      Log an event start message.
      void logEventStart​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.String> map)
      Log an event start message to the INFO Level
      void logEventStart​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.String> map, int level)
      Log an event start message.
      protected static void sanityCheckOnDirectory​(java.io.File dir)
      Checks the destination location for existence, if it can be created, if it is writable etc.
      protected static void sanityCheckOnFile​(java.io.File file)
      Checks the destination location for existence, if it can be created, if it is writable etc.
      void setLevel​(int level)
      Sets the debug level.
      protected abstract void setLevel​(int level, boolean info)
      Sets the debug level.
      void setLevel​(org.apache.log4j.Level level)
      Sets the debug level.
      abstract void setWriters​(java.lang.String out)
      Sets both the output writer and the error writer to the same underlying writer.
      • Methods inherited from class java.lang.Object

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

      • VERSION

        public static final java.lang.String VERSION
        The version of the Logging API
        See Also:
        Constant Field Values
      • PROPERTIES_PREFIX

        public static final java.lang.String PROPERTIES_PREFIX
        Prefix for the property subset to use with the LogManager
        See Also:
        Constant Field Values
      • MESSAGE_DONE_PREFIX

        public static final java.lang.String MESSAGE_DONE_PREFIX
        Suffx for an event completion message.
        See Also:
        Constant Field Values
      • FATAL_MESSAGE_LEVEL

        public static final int FATAL_MESSAGE_LEVEL
        The level value, to indicate a FATAL error message.
        See Also:
        Constant Field Values
      • ERROR_MESSAGE_LEVEL

        public static final int ERROR_MESSAGE_LEVEL
        The level value, to indicate an ERROR message.
        See Also:
        Constant Field Values
      • CONSOLE_MESSAGE_LEVEL

        public static final int CONSOLE_MESSAGE_LEVEL
        The level value, to indicate a CONSOLE error message.
        See Also:
        Constant Field Values
      • WARNING_MESSAGE_LEVEL

        public static final int WARNING_MESSAGE_LEVEL
        The level value, to indicate a WARNING error message.
        See Also:
        Constant Field Values
      • INFO_MESSAGE_LEVEL

        public static final int INFO_MESSAGE_LEVEL
        The level value, to indicate a INFO message.
        See Also:
        Constant Field Values
      • CONFIG_MESSAGE_LEVEL

        public static final int CONFIG_MESSAGE_LEVEL
        The level value, to indicate a CONFIG message.
        See Also:
        Constant Field Values
      • DEBUG_MESSAGE_LEVEL

        public static final int DEBUG_MESSAGE_LEVEL
        The level value, to indicate a DEBUG message.
        See Also:
        Constant Field Values
      • TRACE_MESSAGE_LEVEL

        public static final int TRACE_MESSAGE_LEVEL
        The level value, to indicate a DEBUG message.
        See Also:
        Constant Field Values
      • mLogger

        private static LogManager mLogger
        Ensures only one object is created always. Implements the Singleton.
      • DEFAULT_LOGGER

        public static final java.lang.String DEFAULT_LOGGER
        The default Logger
        See Also:
        Constant Field Values
      • LOG4J_LOGGER

        public static final java.lang.String LOG4J_LOGGER
        The Log4j logger.
        See Also:
        Constant Field Values
      • mDebugLevel

        protected int mDebugLevel
        The debug level. Higher the level the more the detail is logged. At present can be 0 or 1. This is set according to the option given by the user, whether verbose or not.
      • mLogFormatter

        protected LogFormatter mLogFormatter
        The LogFormatter to use to format the message.
    • Constructor Detail

      • LogManager

        public LogManager()
        The constructor.
    • Method Detail

      • getInstance

        public static LogManager getInstance​(java.lang.String logger,
                                             java.lang.String formatter)
        To get a reference to the the object.
        Parameters:
        logger - the logger to use for logging
        formatter - the log formatter to use for formatting messages
        Returns:
        a singleton access to the object.
      • initialize

        public abstract void initialize​(LogFormatter formatter,
                                        java.util.Properties properties)
        Sets the log formatter to use for formatting the messages.
        Parameters:
        formatter - the formatter to use.
        properties - properties that the underlying implementations understand
      • sanityCheckOnFile

        protected static void sanityCheckOnFile​(java.io.File file)
                                         throws java.io.IOException
        Checks the destination location for existence, if it can be created, if it is writable etc.
        Parameters:
        file - is the file to write out to.
        Throws:
        java.io.IOException - in case of error while writing out files.
      • sanityCheckOnDirectory

        protected static void sanityCheckOnDirectory​(java.io.File dir)
                                              throws java.io.IOException
        Checks the destination location for existence, if it can be created, if it is writable etc.
        Parameters:
        dir - is the new base directory to optionally create.
        Throws:
        java.io.IOException - in case of error while writing out files.
      • setLevel

        public void setLevel​(org.apache.log4j.Level level)
        Sets the debug level. All those messages are logged which have a level less than equal to the debug level.
        Parameters:
        level - the level to which the debug level needs to be set to.
      • setLevel

        public void setLevel​(int level)
        Sets the debug level. All those messages are logged which have a level less than equal to the debug level. In addition the console messages are always logged.
        Parameters:
        level - the level to which the debug level needs to be set to.
      • setLevel

        protected abstract void setLevel​(int level,
                                         boolean info)
        Sets the debug level. All those messages are logged which have a level less than equal to the debug level. In case the boolean info is set, all the info messages are also logged.
        Parameters:
        level - the level to which the debug level needs to be set to.
        info - boolean denoting whether the CONSOLE messages need to be logged or not.
      • getLevel

        public abstract int getLevel()
        Returns the debug level.
        Returns:
        the level to which the debug level has been set to.
      • setWriters

        public abstract void setWriters​(java.lang.String out)
        Sets both the output writer and the error writer to the same underlying writer.
        Parameters:
        out - is the name of a file to append to. Special names are stdout and stderr, which map to the system's respective streams.
      • log

        public void log​(int level)
        Log the message represented by the internal log buffer. The log buffer is populated via the add methods.
        Parameters:
        level - the level on which the message has to be logged.
      • logAndReset

        public void logAndReset​(int level)
        Creates a log message with the contents of the internal log buffer. The log buffer is populated via the add methods. It then resets the buffer before logging the log message
        Parameters:
        level - the level on which the message has to be logged.
      • log

        public abstract void log​(java.lang.String message,
                                 java.lang.Exception e,
                                 int level)
        Logs the exception on the appropriate queue if the level of the message is less than or equal to the level set for the Logger. For INFO level message, the boolean indicating that a completion message is to follow is set to true always.
        Parameters:
        message - the message to be logged.
        e - the exception to be logged
        level - the level on which the message has to be logged.
        See Also:
        setLevel(int), log(String,int)
      • logAlreadyFormattedMessage

        protected abstract void logAlreadyFormattedMessage​(java.lang.String message,
                                                           int level)
        A stop gap function .
        Parameters:
        message - already formatted message
        level - the level on which to log.
      • log

        public void log​(java.lang.String message,
                        int level)
        Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger. For INFO level message, the boolean indicating that a completion message is to follow is set to true always.
        Parameters:
        message - the message to be logged.
        level - the level on which the message has to be logged.
        See Also:
        setLevel(int)
      • logEventStart

        public void logEventStart​(java.lang.String name,
                                  java.lang.String entityName,
                                  java.lang.String entityID)
        Log an event start message to INFO level
        Parameters:
        name - the name of the event to be associated
        entityName - the primary entity that is associated with the event e.g. workflow
        entityID - the id of that entity.
      • logEventStart

        public void logEventStart​(java.lang.String name,
                                  java.lang.String entityName,
                                  java.lang.String entityID,
                                  int level)
        Log an event start message.
        Parameters:
        name - the name of the event to be associated
        entityName - the primary entity that is associated with the event e.g. workflow
        entityID - the id of that entity.
        level - the level at which event needs to be logged.
      • logEventStart

        public void logEventStart​(java.lang.String name,
                                  java.util.Map<java.lang.String,​java.lang.String> map)
        Log an event start message to the INFO Level
        Parameters:
        name - the name of the event to be associated
        map - Map indexed by entity name . The values is corresponding EntityID
      • logEventStart

        public void logEventStart​(java.lang.String name,
                                  java.util.Map<java.lang.String,​java.lang.String> map,
                                  int level)
        Log an event start message.
        Parameters:
        name - the name of the event to be associated
        map - Map indexed by entity name . The values is corresponding EntityID
        level - the level to log to
      • logEventCompletion

        public void logEventCompletion()
        Logs the completion message on the basis of the debug level.
      • logEventCompletion

        public abstract void logEventCompletion​(int level)
        Logs the completion message on the basis of the debug level.
        Parameters:
        level - the debug level of the start message for whose completion you want.
      • logEntityHierarchyMessage

        public void logEntityHierarchyMessage​(java.lang.String parentType,
                                              java.lang.String parentID,
                                              java.lang.String childIDType,
                                              java.util.Collection<java.lang.String> childIDs)
        Log a message that connects the parent entities with the children. For e.g. can we use to create the log messages connecting the jobs with the workflow they are part of.
        Parameters:
        parentType - the type of parent entity
        parentID - the id of the parent entity
        childIDType - the type of children entities
        childIDs - Collection of children id's
      • logEntityHierarchyMessage

        public void logEntityHierarchyMessage​(java.lang.String parentType,
                                              java.lang.String parentID,
                                              java.lang.String childIDType,
                                              java.util.Collection<java.lang.String> childIDs,
                                              int level)
        Log a message that connects the parent entities with the children. For e.g. can we use to create the log messages connecting the jobs with the workflow they are part of.
        Parameters:
        parentType - the type of parent entity
        parentID - the id of the parent entity
        childIDType - the type of children entities
        childIDs - Collection of children id's
        level - the logging level.
      • add

        public LogManager add​(java.lang.String value)
        Add to the internal log buffer message a value with the default key. The buffer is logged later when the log() method is called.
        Parameters:
        value -
        Returns:
        self-reference
      • add

        public LogManager add​(java.lang.String key,
                              java.lang.String value)
        Add to the internal log buffer message a value with the key oassed The buffer is logged later when the log() method is called.
        Parameters:
        key -
        value -
        Returns:
        Self-reference, so calls can be chained