Class Logger

  • All Implemented Interfaces:
    AppenderAttachable
    Direct Known Subclasses:
    NOPLogger, RootCategory, RootLogger

    public class Logger
    extends Category
    This is the central class in the log4j package. Most logging operations, except configuration, are done through this class.
    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.

        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.

      • 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 Category.debug(Object) form for more detailed information.

        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
        Since:
        1.2.12
      • isTraceEnabled

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