Class PerfLogger


  • public final class PerfLogger
    extends java.lang.Object
    This class is a kind of performance logger to be able to log the execution times of methods or code segments which may need a little bit longer. It can be used as a replacement of a normal logger.

    We use a LogWatch to measure the times between a start(String, Object...) and end(String, Object...) call. We store this LogWatch as ThreadLocal because loggers are normally used as static variables. So we can be sure that each thread has its own LogWatch.

    Since:
    1.4.1 (17.03.2014)
    Version:
    $Revision: 1.12 $
    Author:
    oliver
    • Constructor Summary

      Constructors 
      Constructor Description
      PerfLogger()
      Instantiates a new perf logger.
      PerfLogger​(java.lang.Class<?> clazz)
      Instantiates a new perf logger.
      PerfLogger​(org.apache.logging.log4j.Logger logger)
      Instantiates a new perf logger.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void debug​(java.lang.String format, java.lang.Object... args)
      Debug.
      void end​(int logLevel, java.lang.String format, java.lang.Object... args)
      End the log with the given message.
      void end​(java.lang.String format, java.lang.Object... args)
      End the log with the given message.
      void error​(java.lang.String format, java.lang.Object... args)
      Error.
      void info​(java.lang.String format, java.lang.Object... args)
      Info.
      boolean isDebugEnabled()
      Checks if is debug enabled.
      void log​(int level, java.lang.String format, java.lang.Object... args)
      Log.
      void start​(int level, java.lang.String format, java.lang.Object... args)
      Start the log for the given message.
      void start​(java.lang.String format, java.lang.Object... args)
      Start the log for the given message.
      void trace​(java.lang.String format, java.lang.Object... args)
      Trace.
      void warn​(java.lang.String format, java.lang.Object... args)
      Warn.
      • Methods inherited from class java.lang.Object

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

      • PerfLogger

        public PerfLogger()
        Instantiates a new perf logger.
      • PerfLogger

        public PerfLogger​(java.lang.Class<?> clazz)
        Instantiates a new perf logger.
        Parameters:
        clazz - the clazz
      • PerfLogger

        public PerfLogger​(org.apache.logging.log4j.Logger logger)
        Instantiates a new perf logger.
        Parameters:
        logger - the logger
    • Method Detail

      • start

        public void start​(java.lang.String format,
                          java.lang.Object... args)
        Start the log for the given message. The default level for the logged message is "INFO".
        Parameters:
        format - the format
        args - the args
      • start

        public void start​(int level,
                          java.lang.String format,
                          java.lang.Object... args)
        Start the log for the given message. For the valid log levels see
        Parameters:
        level - the level
        format - the format
        args - the args SimpleLog.
        See Also:
        SimpleLog
      • end

        public void end​(java.lang.String format,
                        java.lang.Object... args)
        End the log with the given message. The output will contain the measure time from the last start(String, Object...) log. So be sure to call one of the start methods before.

        The default level for the logged message is "INFO".

        Parameters:
        format - the format
        args - the args
      • end

        public void end​(int logLevel,
                        java.lang.String format,
                        java.lang.Object... args)
        End the log with the given message. The output will contain the measure time from the last start(String, Object...) log. So be sure to call one of the start methods before.

        It is recommended to use the same as in

        Parameters:
        logLevel - the log level
        format - the format
        args - the args start(int, String, Object...). If the reported times is greater than 1 minute the log level will be increased at least to "INFO".

      • log

        public void log​(int level,
                        java.lang.String format,
                        java.lang.Object... args)
        Log.
        Parameters:
        level - the level
        format - the format
        args - the args
      • error

        public void error​(java.lang.String format,
                          java.lang.Object... args)
        Error.
        Parameters:
        format - the format
        args - the args
      • warn

        public void warn​(java.lang.String format,
                         java.lang.Object... args)
        Warn.
        Parameters:
        format - the format
        args - the args
      • info

        public void info​(java.lang.String format,
                         java.lang.Object... args)
        Info.
        Parameters:
        format - the format
        args - the args
      • debug

        public void debug​(java.lang.String format,
                          java.lang.Object... args)
        Debug.
        Parameters:
        format - the format
        args - the args
      • trace

        public void trace​(java.lang.String format,
                          java.lang.Object... args)
        Trace.
        Parameters:
        format - the format
        args - the args
      • isDebugEnabled

        public boolean isDebugEnabled()
        Checks if is debug enabled.
        Returns:
        true, if is debug enabled