@NotThreadSafe public class PerformanceLogger extends Object
This class is meant to be used like this:
//...
PerformanceLogger plog = new PerformanceLogger();
doWork();
plog.logElapsedAndRestart();
doSomeMoreWork();
plog.logElapsed();
//...
For logging SLF4J with log level DEBUG is used; you can therefore disable
performance logging by simply setting the log level for this class accordingly.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_PERFORMANCE_LOG_FORMATTER_KEY
The property key that specifies the default
PerformanceLogFormatter implementation to use. |
static String |
DEFAULT_SETTINGS_PATH
Path to an XML properties file that can be used to override the default settings of this class.
|
static String |
DEFAULT_THRESHOLD_KEY
The property key that specifies the default threshold to use.
|
| Constructor and Description |
|---|
PerformanceLogger()
Constructs a new
PerformanceLogger with default settings. |
PerformanceLogger(long threshold)
Constructs a new
PerformanceLogger a default PerformanceLogFormatter implementation. |
PerformanceLogger(long threshold,
PerformanceLogFormatter logFormatter)
Constructs a new
PerformanceLogger. |
PerformanceLogger(PerformanceLogFormatter logFormatter)
Constructs a new
PerformanceLogger with a default threshold. |
| Modifier and Type | Method and Description |
|---|---|
void |
logElapsed()
See
logElapsed(String). |
void |
logElapsed(String msg)
Logs the elapsed time if it is above the threshold.
|
void |
logElapsedAndRestart()
|
void |
logElapsedAndRestart(String msg)
Logs the elapsed time if it is above the threshold and restarts the internal timer.
|
void |
restart()
Restarts the internal timer.
|
public static final String DEFAULT_SETTINGS_PATH
This file loaded using LocalResources. Consult the users manual for details.
public static final String DEFAULT_PERFORMANCE_LOG_FORMATTER_KEY
PerformanceLogFormatter implementation to use.DEFAULT_SETTINGS_PATH,
Constant Field Valuespublic static final String DEFAULT_THRESHOLD_KEY
DEFAULT_SETTINGS_PATH,
Constant Field Valuespublic PerformanceLogger()
PerformanceLogger with default settings.public PerformanceLogger(long threshold)
PerformanceLogger a default PerformanceLogFormatter implementation.threshold - the threshold in ms for which the logger should generate any output.public PerformanceLogger(PerformanceLogFormatter logFormatter)
PerformanceLogger with a default threshold.logFormatter - optional PerformanceLogFormatterpublic PerformanceLogger(long threshold,
PerformanceLogFormatter logFormatter)
PerformanceLogger.threshold - the threshold in ms for which the logger should generate any output.logFormatter - optional PerformanceLogFormatter.public void logElapsed()
logElapsed(String).public void logElapsedAndRestart()
public void logElapsed(String msg)
msg - an optional message.public void logElapsedAndRestart(String msg)
msg - an optional message.public void restart()
Copyright © 2012-2013. All Rights Reserved.