Class Logger


  • public class Logger
    extends java.lang.Object
    A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.swing. In additon it is possible to create "anonymous" Loggers that are not stored in the Logger namespace.

    Logger objects may be obtained by calls on one of the getLogger factory methods. These will either create a new Logger or return a suitable existing Logger.

    Logging messages will be forwarded to registered Handler objects, which can forward the messages to a variety of destinations, including consoles, files, OS logs, etc.

    Each Logger keeps track of a "parent" Logger, which is its nearest existing ancestor in the Logger namespace.

    Each Logger has a "Level" associated with it. This reflects a minimum Level that this logger cares about - default level is Level.OFF.

    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List handlers  
      protected boolean publishToRoot  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Logger​(java.lang.String loggerName)
      Protected method to construct a logger for a named subsystem.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHandler​(Handler handler)
      Add a log Handler to receive logging messages.
      void entering​(java.lang.String className, java.lang.String methodName)
      Log a method entry.
      void entering​(java.lang.String className, java.lang.String methodName, java.lang.Object singleArg)
      Log a method entry, with one parameter.
      void entering​(java.lang.String className, java.lang.String methodName, java.lang.Object[] args)
      Log a method entry, with an array of parameters.
      void exiting​(java.lang.String className, java.lang.String methodName)
      Log a method return.
      void exiting​(java.lang.String className, java.lang.String methodName, java.lang.Object result)
      Log a method return, with result object.
      Filter getFilter()  
      Handler[] getHandlers()
      Get the Handlers associated with this logger.
      Level getLevel()
      Get the log Level that has been specified for this Logger.
      java.lang.String getName()
      Get the name for this logger.
      boolean isLoggable​(Level level)
      Check if a message of the given level would actually be logged by this logger.
      boolean isPublishToRoot()  
      void log​(Level level, java.lang.String message)
      Log a message, with no arguments.
      void log​(LogRecord logRecord)
      Log a LogRecord.
      void logp​(Level level, java.lang.String className, java.lang.String methodName, java.lang.String message)
      Log a message, specifying source class and method, with no arguments.
      void logp​(Level level, java.lang.String className, java.lang.String methodName, java.lang.String message, java.lang.Object singleArg)
      Log a message, specifying source class and method, with a single object parameter to the log message.
      void logp​(Level level, java.lang.String className, java.lang.String methodName, java.lang.String message, java.lang.Object[] args)
      Log a message, specifying source class and method, with an array of object arguments.
      void logp​(Level level, java.lang.String className, java.lang.String methodName, java.lang.String message, java.lang.Throwable thrown)
      Log a message, specifying source class and method, with associated Throwable information.
      void removeHandler​(Handler handler)
      Remove a log Handler.
      void setFilter​(Filter filter)
      Set a filter to control output on this Logger.
      void setLevel​(Level level)
      Set the log level specifying which message levels will be logged by this logger.
      void throwing​(java.lang.String className, java.lang.String methodName, java.lang.Throwable thrown)
      Log throwing an exception.
      java.lang.String toString()
      Returns a string representation of the object
      • Methods inherited from class java.lang.Object

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

      • handlers

        protected java.util.List handlers
      • publishToRoot

        protected boolean publishToRoot
    • Constructor Detail

      • Logger

        protected Logger​(java.lang.String loggerName)
        Protected method to construct a logger for a named subsystem.
        Parameters:
        loggerName - A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem
    • Method Detail

      • getHandlers

        public Handler[] getHandlers()
        Get the Handlers associated with this logger.

        Returns:
        an array of all registered Handlers
      • addHandler

        public void addHandler​(Handler handler)
        Add a log Handler to receive logging messages.
        Parameters:
        handler - a logging Handler
      • removeHandler

        public void removeHandler​(Handler handler)
        Remove a log Handler.
        Parameters:
        handler - a logging Handler
      • entering

        public void entering​(java.lang.String className,
                             java.lang.String methodName)
        Log a method entry.

        This is a convenience method that can be used to log entry to a method. className LogRecord with message "ENTRY", log level FINER, and the given sourceMethod and sourceClass is logged.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of method that is being entered
      • entering

        public void entering​(java.lang.String className,
                             java.lang.String methodName,
                             java.lang.Object singleArg)
        Log a method entry, with one parameter.

        This is a convenience method that can be used to log entry to a method. A LogRecord with message "ENTRY {0}", log level FINER, and the given sourceMethod, sourceClass, and parameter is logged.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of method that is being entered
        singleArg - parameter to the method being entered
      • entering

        public void entering​(java.lang.String className,
                             java.lang.String methodName,
                             java.lang.Object[] args)
        Log a method entry, with an array of parameters.

        This is a convenience method that can be used to log entry to a method. A LogRecord with message "ENTRY" (followed by a format {N} indicator for each entry in the parameter array), log level FINER, and the given sourceMethod, sourceClass, and parameters is logged.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of method that is being entered
        args - array of parameters to the method being entered
      • exiting

        public void exiting​(java.lang.String className,
                            java.lang.String methodName)
        Log a method return.

        This is a convenience method that can be used to log returning from a method. A LogRecord with message "RETURN", log level FINER, and the given sourceMethod and sourceClass is logged.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of the method
      • exiting

        public void exiting​(java.lang.String className,
                            java.lang.String methodName,
                            java.lang.Object result)
        Log a method return, with result object.

        This is a convenience method that can be used to log returning from a method. A LogRecord with message "RETURN {0}", log level FINER, and the gives sourceMethod, sourceClass, and result object is logged.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of the method
        result - Object that is being returned
      • getFilter

        public Filter getFilter()
      • getLevel

        public Level getLevel()
        Get the log Level that has been specified for this Logger. The result may be null, which means that this logger's effective level will be inherited from its parent.
        Returns:
        this Logger's level
      • getName

        public java.lang.String getName()
        Get the name for this logger.
        Returns:
        logger name. Will be null for anonymous Loggers.
      • isLoggable

        public boolean isLoggable​(Level level)
        Check if a message of the given level would actually be logged by this logger. This check is based on the Loggers effective level, which may be inherited from its parent.
        Parameters:
        level - a message logging level
        Returns:
        true if the given message level is currently being logged.
      • log

        public void log​(LogRecord logRecord)
        Log a LogRecord.

        All the other logging methods in this class call through this method to actually perform any logging. Subclasses can override this single method to capture all log activity.

        Parameters:
        logRecord - the LogRecord to be published
      • logp

        public void logp​(Level level,
                         java.lang.String className,
                         java.lang.String methodName,
                         java.lang.String message)
        Log a message, specifying source class and method, with no arguments.

        If the logger is currently enabled for the given message level then the given message is forwarded to all the registered output Handler objects.

        Parameters:
        level - One of the message level identifiers, e.g. SEVERE
        className - name of class that issued the logging request
        methodName - name of method that issued the logging request
        message - The string message (or a key in the message catalog)
      • logp

        public void logp​(Level level,
                         java.lang.String className,
                         java.lang.String methodName,
                         java.lang.String message,
                         java.lang.Object singleArg)
        Log a message, specifying source class and method, with a single object parameter to the log message.

        If the logger is currently enabled for the given message level then a corresponding LogRecord is created and forwarded to all the registered output Handler objects.

        Parameters:
        level - One of the message level identifiers, e.g. SEVERE
        className - name of class that issued the logging request
        methodName - name of method that issued the logging request
        message - The string message (or a key in the message catalog)
        singleArg - Parameter to the log message.
      • logp

        public void logp​(Level level,
                         java.lang.String className,
                         java.lang.String methodName,
                         java.lang.String message,
                         java.lang.Object[] args)
        Log a message, specifying source class and method, with an array of object arguments.

        If the logger is currently enabled for the given message level then a corresponding LogRecord is created and forwarded to all the registered output Handler objects.

        Parameters:
        level - One of the message level identifiers, e.g. SEVERE
        className - name of class that issued the logging request
        methodName - name of method that issued the logging request
        message - The string message (or a key in the message catalog)
        args - Array of parameters to the message
      • logp

        public void logp​(Level level,
                         java.lang.String className,
                         java.lang.String methodName,
                         java.lang.String message,
                         java.lang.Throwable thrown)
        Log a message, specifying source class and method, with associated Throwable information.

        If the logger is currently enabled for the given message level then the given arguments are stored in a LogRecord which is forwarded to all registered output handlers.

        Note that the thrown argument is stored in the LogRecord thrown property, rather than the LogRecord parameters property. Thus is it processed specially by output Formatters and is not treated as a formatting parameter to the LogRecord message property.

        Parameters:
        level - One of the message level identifiers, e.g. SEVERE
        className - name of class that issued the logging request
        methodName - name of method that issued the logging request
        message - The string message (or a key in the message catalog)
        thrown - Throwable associated with log message.
      • log

        public void log​(Level level,
                        java.lang.String message)
        Log a message, with no arguments.

        If the logger is currently enabled for the given message level then the given message is forwarded to all the registered output Handler objects.

        Parameters:
        level - One of the message level identifiers, e.g. SEVERE
        message - The string message (or a key in the message catalog)
      • setFilter

        public void setFilter​(Filter filter)
        Set a filter to control output on this Logger.

        After passing the initial "level" check, the Logger will call this Filter to check if a log record should really be published.

        Parameters:
        filter - a filter object (may be null)
      • setLevel

        public void setLevel​(Level level)
        Set the log level specifying which message levels will be logged by this logger. Message levels lower than this value will be discarded. The level value Level.OFF can be used to turn off logging.

        If the new level is null, it means that this node should inherit its level from its nearest ancestor with a specific (non-null) level value.

        Parameters:
        level - the new value for the log level (may be null)
      • isPublishToRoot

        public boolean isPublishToRoot()
      • throwing

        public void throwing​(java.lang.String className,
                             java.lang.String methodName,
                             java.lang.Throwable thrown)
        Log throwing an exception.

        This is a convenience method to log that a method is terminating by throwing an exception. The logging is done using the FINER level.

        If the logger is currently enabled for the given message level then the given arguments are stored in a LogRecord which is forwarded to all registered output handlers. The LogRecord's message is set to "THROW".

        Note that the thrown argument is stored in the LogRecord thrown property, rather than the LogRecord parameters property. Thus is it processed specially by output Formatters and is not treated as a formatting parameter to the LogRecord message property.

        Parameters:
        className - name of class that issued the logging request
        methodName - name of the method.
        thrown - The Throwable that is being thrown.
      • toString

        public java.lang.String toString()
        Returns a string representation of the object
        Overrides:
        toString in class java.lang.Object