Class Logger


  • public class Logger
    extends java.lang.Object
    TestNG logging now uses slf4j logging facade to satisfy the logging needs. To control TestNG logging, please refer to the SLF4J logging facade documentation. TestNG internally uses SimpleLogger for logging purposes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void debug​(java.lang.Object message)
      Log a message object with the DEBUG level.
      void debug​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter.
      void error​(java.lang.Object message)
      Log a message object with the ERROR level.
      void error​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter.
      void fatal​(java.lang.Object message)
      Log a message object with the FATAL level.
      void fatal​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the FATAL level including the stack trace of the Throwable t passed as parameter.
      static Logger getLogger​(java.lang.Class<?> pClass)
      Retrieve a logger named according to the value of the pClass.getName() parameter.
      void info​(java.lang.Object message)
      Log a message object with the INFO level.
      void info​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the WARN level including the stack trace of the Throwable t passed as parameter.
      boolean isDebugEnabled()
      Check whether this logger is enabled for the DEBUG Level.
      boolean isInfoEnabled()
      Check whether this logger is enabled for the INFO Level.
      boolean isTraceEnabled()
      Check whether this logger is enabled for the TRACE Level.
      void trace​(java.lang.Object message)
      Log a message object with the TRACE level.
      void trace​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the TRACE level including the stack trace of the Throwable t passed as parameter.
      void warn​(java.lang.Object message)
      Log a message object with the WARN level.
      void warn​(java.lang.Object message, java.lang.Throwable t)
      Log a message object with the ERROR level including the stack trace of the Throwable t passed as parameter.
      • Methods inherited from class java.lang.Object

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

      • getLogger

        public static Logger getLogger​(java.lang.Class<?> pClass)
        Retrieve a logger named according to the value of the pClass.getName() 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 nearest ancestor with a set level.
        Parameters:
        pClass - The class' logger to retrieve.
        Returns:
        a logger named according to the value of the pClass.getName().
      • isTraceEnabled

        public boolean isTraceEnabled()
        Check whether this logger is enabled for the TRACE Level.
        Returns:
        true if this logger is enabled for level TRACE, false otherwise.
      • trace

        public void trace​(java.lang.Object message)
        Log a message object with the TRACE level. This method first checks if this logger is TRACE enabled. If this logger is TRACE enabled, then it converts the message object (passed as parameter) to a string by invoking toString(). 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 trace(Object, Throwable) form instead.
        Parameters:
        message - the message object to log.
      • trace

        public void trace​(java.lang.Object message,
                          java.lang.Throwable t)
        Log a message object with the TRACE level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • isDebugEnabled

        public boolean isDebugEnabled()
        Check whether this logger is enabled for the DEBUG Level.
        Returns:
        true if this logger is enabled for level DEBUG, false otherwise.
      • debug

        public void debug​(java.lang.Object message)
        Log a message object with the DEBUG level. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
      • debug

        public void debug​(java.lang.Object message,
                          java.lang.Throwable t)
        Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object, Throwable) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • isInfoEnabled

        public boolean isInfoEnabled()
        Check whether this logger is enabled for the INFO Level.
        Returns:
        true if this logger is enabled for level INFO, false otherwise.
      • info

        public void info​(java.lang.Object message)
        Log a message object with the INFO level. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
      • info

        public void info​(java.lang.Object message,
                         java.lang.Throwable t)
        Log a message object with the WARN level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object, Throwable) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • warn

        public void warn​(java.lang.Object message)
        Log a message object with the WARN level. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
      • warn

        public void warn​(java.lang.Object message,
                         java.lang.Throwable t)
        Log a message object with the ERROR level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object, Throwable) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • error

        public void error​(java.lang.Object message)
        Log a message object with the ERROR level. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
      • error

        public void error​(java.lang.Object message,
                          java.lang.Throwable t)
        Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object, Throwable) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.
      • fatal

        public void fatal​(java.lang.Object message)
        Log a message object with the FATAL level. See Logger.trace(Object) form for more detailed information.
        Parameters:
        message - the message object to log.
      • fatal

        public void fatal​(java.lang.Object message,
                          java.lang.Throwable t)
        Log a message object with the FATAL level including the stack trace of the Throwable t passed as parameter. See Logger.trace(Object, Throwable) form for more detailed information.
        Parameters:
        message - the message object to log.
        t - the exception to log, including its stack trace.