Class Logger

  • All Implemented Interfaces:
    org.apache.log4j.spi.AppenderAttachable, PaxLoggingManagerAwareLogger

    public class Logger
    extends Category
    This is the central class in the log4j package. Most logging operations, except configuration, are done through this class. pax-logging-api has to treat this class both as a factory and as logger itself - with all the configuration-related consequences.
    Since:
    log4j 1.2
    Author:
    Ceki Gülcü
    • Constructor Detail

      • Logger

        protected Logger​(String name)
    • Method Detail

      • getLogger

        public static Logger getLogger​(String name)
        Retrieve a logger named according to the value of the name parameter. If the named logger already exists, then the existing instance will be returned. Otherwise, a new instance is created.

        By default, loggers do not have a set level but inherit it from their neareast ancestor with a set level. This is one of the central features of log4j.

        In pax-logging, loggers are obtained from current or fallback PaxLoggingManager

        Parameters:
        name - The name of the logger to retrieve.
      • getLogger

        public static Logger getLogger​(Class clazz)
        Shorthand for getLogger(clazz.getName()).
        Parameters:
        clazz - The name of clazz will be used as the name of the logger to retrieve. See getLogger(String) for more detailed information.
      • getRootLogger

        public static Logger getRootLogger()
        Return the root logger for the current logger repository.

        The Logger.getName() method for the root logger always returns string value: "root". However, calling Logger.getLogger("root") does not retrieve the root logger but a logger just under root named "root".

        In other words, calling this method is the only way to retrieve the root logger.

      • getLogger

        public static Logger getLogger​(String name,
                                       org.apache.log4j.spi.LoggerFactory factory)
        Like getLogger(String) except that the type of logger instantiated depends on the type returned by the LoggerFactory.makeNewLoggerInstance(java.lang.String) method of the factory parameter.

        This method is intended to be used by sub-classes.

        Parameters:
        name - The name of the logger to retrieve.
        factory - A LoggerFactory implementation that will actually create a new Instance.
        Since:
        0.8.5
      • trace

        public void trace​(Object message,
                          Throwable t)
        Log a message object with the TRACE level including the stack trace of the Throwablet passed as parameter.

        See debug(Object) form for more detailed information.

        Overrides:
        trace in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
        Since:
        1.2.12
      • trace

        public void trace​(Object messagePattern,
                          Object arg)
        Description copied from class: Category
        Log a message with the TRACE level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        trace in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • trace

        public void trace​(String messagePattern,
                          Object arg1,
                          Object arg2)
        Description copied from class: Category
        Log a message with the TRACE level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        trace in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • isTraceEnabled

        public boolean isTraceEnabled()
        Check whether this category is enabled for the TRACE Level.
        Overrides:
        isTraceEnabled in class Category
        Returns:
        boolean - true if this category is enabled for level TRACE, false otherwise.
        Since:
        1.2.12
      • debug

        public void debug​(Object message)
        Description copied from class: Category
        Log a message object with the DEBUG level.

        This method first checks if this category is DEBUG enabled by comparing the level of this category with the DEBUG level. If this category is DEBUG enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate ObjectRenderer. It then proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

        WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.debug(Object, Throwable) form instead.

        Overrides:
        debug in class Category
        Parameters:
        message - the message object to log.
      • debug

        public void debug​(Object message,
                          Throwable t)
        Description copied from class: Category
        Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter.

        See Category.debug(Object) form for more detailed information.

        Overrides:
        debug in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • debug

        public void debug​(Object messagePattern,
                          Object arg)
        Description copied from class: Category
        Log a message with the DEBUG level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        debug in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • debug

        public void debug​(String messagePattern,
                          Object arg1,
                          Object arg2)
        Description copied from class: Category
        Log a message with the DEBUG level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        debug in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • error

        public void error​(Object message)
        Description copied from class: Category
        Log a message object with the ERROR Level.

        This method first checks if this category is ERROR enabled by comparing the level of this category with ERROR Level. If this category is ERROR enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

        WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.error(Object, Throwable) form instead.

        Overrides:
        error in class Category
        Parameters:
        message - the message object to log
      • error

        public void error​(Object message,
                          Throwable t)
        Description copied from class: Category
        Log a message object with the ERROR level including the stack trace of the Throwable t passed as parameter.

        See Category.error(Object) form for more detailed information.

        Overrides:
        error in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • error

        public void error​(Object messagePattern,
                          Object arg)
        Description copied from class: Category
        Log a message with the ERROR level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        error in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • error

        public void error​(String messagePattern,
                          Object arg1,
                          Object arg2)
        Description copied from class: Category
        Log a message with the ERROR level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        error in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • fatal

        public void fatal​(Object message)
        Description copied from class: Category
        Log a message object with the FATAL Level.

        This method first checks if this category is FATAL enabled by comparing the level of this category with FATAL Level. If the category is FATAL enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

        WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.fatal(Object, Throwable) form instead.

        Overrides:
        fatal in class Category
        Parameters:
        message - the message object to log
      • fatal

        public void fatal​(Object message,
                          Throwable t)
        Description copied from class: Category
        Log a message object with the FATAL level including the stack trace of the Throwable t passed as parameter.

        See Category.fatal(Object) for more detailed information.

        Overrides:
        fatal in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • fatal

        public void fatal​(Object messagePattern,
                          Object arg)
        Description copied from class: Category
        Log a message with the FATAL level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        fatal in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • fatal

        public void fatal​(String messagePattern,
                          Object arg1,
                          Object arg2)
        Description copied from class: Category
        Log a message with the FATAL level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        fatal in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • info

        public void info​(Object message)
        Description copied from class: Category
        Log a message object with the INFO Level.

        This method first checks if this category is INFO enabled by comparing the level of this category with INFO Level. If the category is INFO enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

        WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.info(Object, Throwable) form instead.

        Overrides:
        info in class Category
        Parameters:
        message - the message object to log
      • info

        public void info​(Object message,
                         Throwable t)
        Description copied from class: Category
        Log a message object with the INFO level including the stack trace of the Throwable t passed as parameter.

        See Category.info(Object) for more detailed information.

        Overrides:
        info in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • info

        public void info​(Object messagePattern,
                         Object arg)
        Description copied from class: Category
        Log a message with the INFO level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        info in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • info

        public void info​(String messagePattern,
                         Object arg1,
                         Object arg2)
        Description copied from class: Category
        Log a message with the INFO level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        info in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • warn

        public void warn​(Object message)
        Description copied from class: Category
        Log a message object with the WARN Level.

        This method first checks if this category is WARN enabled by comparing the level of this category with WARN Level. If the category is WARN enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hieararchy depending on the value of the additivity flag.

        WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.warn(Object, Throwable) form instead.

        Overrides:
        warn in class Category
        Parameters:
        message - the message object to log.
      • warn

        public void warn​(Object message,
                         Throwable t)
        Description copied from class: Category
        Log a message with the WARN level including the stack trace of the Throwable t passed as parameter.

        See Category.warn(Object) for more detailed information.

        Overrides:
        warn in class Category
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • warn

        public void warn​(Object messagePattern,
                         Object arg)
        Description copied from class: Category
        Log a message with the WARN level with message formatting done according to the value of messagePattern and arg parameters.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        warn in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
      • warn

        public void warn​(String messagePattern,
                         Object arg1,
                         Object arg2)
        Description copied from class: Category
        Log a message with the WARN level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

        This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

        Overrides:
        warn in class Category
        Parameters:
        messagePattern - The message pattern which will be parsed and formatted
        arg1 - The first argument to replace the first formatting element
        arg2 - The second argument to replace the second formatting element
      • assertLog

        public void assertLog​(boolean assertion,
                              String msg)
        Description copied from class: Category
        If assertion parameter is false, then logs msg as an error statement.

        The assert method has been renamed to assertLog because assert is a language reserved word in JDK 1.4.

        Overrides:
        assertLog in class Category
        msg - The message to print if assertion is false.
      • log

        public void log​(Priority priority,
                        Object message)
        Description copied from class: Category
        This generic form is intended to be used by wrappers.
        Overrides:
        log in class Category
      • log

        public void log​(String callerFQCN,
                        Priority level,
                        Object message,
                        Throwable t)
        Description copied from class: Category
        This is the most generic printing method. It is intended to be invoked by wrapper classes.
        Overrides:
        log in class Category
        Parameters:
        callerFQCN - The wrapper class' fully qualified class name.
        level - The level of the logging request.
        message - The message of the logging request.
        t - The throwable of the logging request, may be null.