Class LogManager


  • public final class LogManager
    extends Object
    This class represents the interface to a single logging framework that is easily accessible by any component. Using the LogManager, a component can quickly submit a log message, and can rely upon the LogManager to determine (a) whether that message is to be recorded or discarded; and (b) where to send any recorded messages. Thus, the component's code that submits messages does not have to be modified to alter the logging behavior of the application.

    By default, all context(s) are logged by the LogManager. The messages that the LogManager actually records and sends to the destinations can be controlled using two different and orthogonal parameters. The first is a message level that filters messages based upon detail, and the second is a message context that filters messages based upon origin. The LogManager tracks only those context(s) that should NOT be logged. Only if a message (which also is defined with these two parameters) passes both filters will it be sent to the destinations.

    Each message is submitted with one of the following levels (determined by the particular method used to submit the message), sorted from the least detailed to the greatest:

    • Critical: This level of message is generally used to record an event or error that must be recorded (if any logging is used). If it is used to record an error, it generally means that the system encountered a critical error which affects the integrity, accuracy, reliability and/or capability of the system.
    • Error: Error messages are generally used to record unexpected problems, or errors that are not critical in nature and from which the system can automatically recover.
    • Warning: Warning messages generally described expected errors from which the system should recover. However, this level is used to record the fact that such an error or event did occur.
    • Information: This level of logging is the usually the normal level. All interesting periodic events should be logged at this level so someone looking through the log can see the amount and kind of processing happening in the system.
    • Detail: Such messages are moderately detailed, and help to debug typical problems in the system. Generally, these messages are not so detailed that the big picture gets lost.
    • Trace: A trace message is the most detailed logging level, used to trace system execution for really nasty problems. At this level, logging will be so verbose that the system performance may be affected.

    The context for a message is any application-specified String. Again, only those message contexts that match those in the LogManager's configuration will be sent to the destinations.

    • Constructor Detail

      • LogManager

        public LogManager()
    • Method Detail

      • logCritical

        public static void logCritical​(String context,
                                       Object message)
        Send a critical message to the log. This level of message is generally used to record an event or error that must be recorded (if any logging is used). If it is used to record an error, it generally means that the system encountered a critical error which affects the integrity, accuracy, reliability and/or capability of the system.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        message - the log message; the message is not logged if this parameter is null
      • logCritical

        public static void logCritical​(String context,
                                       Throwable e,
                                       Object message)
        Send a critical message to the log. This level of message is generally used to record an event or error that must be recorded (if any logging is used). If it is used to record an error, it generally means that the system encountered a critical error which affects the integrity, accuracy, reliability and/or capability of the system.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        message - the log message (may be null)
      • logError

        public static void logError​(String context,
                                    Object message)
        Send an error message to the log. Error messages are generally used to record unexpected problems, or errors that are not critical in nature and from which the system can automatically recover.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        message - the log message; the message is not logged if this parameter is null
      • logError

        public static void logError​(String context,
                                    Throwable e,
                                    Object message)
        Send an error message to the log. Error messages are generally used to record unexpected problems, or errors that are not critical in nature and from which the system can automatically recover.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        message - the log message (may be null)
      • logWarning

        public static void logWarning​(String context,
                                      Object message)
        Send a warning message to the log. Warning messages generally described expected errors from which the system should recover. However, this level is used to record the fact that such an error or event did occur.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        message - the log message; the message is not logged if this parameter is null
      • logWarning

        public static void logWarning​(String context,
                                      Throwable e,
                                      Object message)
        Send a warning message to the log. Warning messages generally described expected errors from which the system should recover. However, this level is used to record the fact that such an error or event did occur.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        message - the log message (may be null)
      • logInfo

        public static void logInfo​(String context,
                                   Object message)
        Send a information message to the log. This level of logging is the usually the normal level. All interesting periodic events should be logged at this level so someone looking through the log can see the amount and kind of processing happening in the system.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        message - the log message; the message is not logged if this parameter is null
      • logDetail

        public static void logDetail​(String context,
                                     Object msgPart)
        Send a detail message to the log. Such messages are moderately detailed, and help to debug typical problems in the system. Generally, these messages are not so detailed that the big picture gets lost.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        msgPart - the individual parts of the log message; the message is not logged if this parameter is null
      • logDetail

        public static void logDetail​(String context,
                                     Object msgPart,
                                     Object msgPart1)
      • logDetail

        public static void logDetail​(String context,
                                     Object... msgParts)
      • logDetail

        public static void logDetail​(String context,
                                     Throwable e,
                                     Object... message)
        Send a detail message to the log. Such messages are moderately detailed, and help to debug typical problems in the system. Generally, these messages are not so detailed that the big picture gets lost.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        message - the log message (may be null)
      • logTrace

        public static void logTrace​(String context,
                                    Object... msgParts)
        Send a trace message to the log. A trace message is the most detailed logging level, used to trace system execution for really nasty problems. At this level, logging will be so verbose that the system performance may be affected.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        msgParts - the individual parts of the log message; the message is not logged if this parameter is null
      • logTrace

        public static void logTrace​(String context,
                                    Object msgPart)
      • logTrace

        public static void logTrace​(String context,
                                    Object msgPart,
                                    Object msgPart1)
      • logTrace

        public static void logTrace​(String context,
                                    Throwable e,
                                    Object... msgParts)
        Send a trace message to the log. A trace message is the most detailed logging level, used to trace system execution for really nasty problems. At this level, logging will be so verbose that the system performance may be affected.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        msgParts - the individual parts of the log message (may be null)
      • log

        public static void log​(int msgLevel,
                               String context,
                               Object message)
        Send a message of the specified level to the log.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        msgLevel -
        context - the context for this log message (for example, the component that is generating this message).
        message - the individual parts of the log message; the message is not logged if this parameter is null
      • log

        public static void log​(int msgLevel,
                               String context,
                               Throwable e,
                               Object... message)
        Send a message of the specified level to the log.

        Only if the log manager is configured to send such messages to the destination will the message be recorded.

        Parameters:
        context - the context for this log message (for example, the component that is generating this message).
        e - the exception that is to be logged; the message is not logged if this parameter is null
        message - the individual parts of the log message; the message is not logged if this parameter is null
      • setLogListener

        public static Logger setLogListener​(Logger listener)
      • isMessageToBeRecorded

        public static boolean isMessageToBeRecorded​(String context,
                                                    int msgLevel)
        Utility method to identify whether a log message with the specified context and level will be recorded in the LogManager's destinations.
        Parameters:
        context -
        msgLevel -
        Returns:
        true if the message would be recorded if sent to the LogManager, or false if it would be discarded by the LogManager.
      • createLoggingProxy

        public static Object createLoggingProxy​(String loggingContext,
                                                Object instance,
                                                Class<?>[] interfaces,
                                                int level)
        Create a logging proxy, that logs at entry and exit points of the method calls on the provided interfaces.
      • putMdc

        public static void putMdc​(String key,
                                  String val)
      • removeMdc

        public static void removeMdc​(String key)