Class TimeLog
java.lang.Object
org.nuiton.util.TimeLog
Cette classe permet de facilement trace le temps d'execution entre deux points
usage
final private static final Log log = LogFactory.getLog(MyClass.class);
final static private TimeLog timeLog = new TimeLog(MyClass.class, 5000, 1000);
long start = timeLog.getTime();
...
// do some work
...
start = timeLog.log(start, "MyMethod step 1", "do some work");
...
// do some work
...
timeLog.log(start, "MyMethod step 2", "do other work");
System.out.println ("time: " + timeLog.getCallCount());
You can configure log level in configuration file with:
log4j.logger.org.codelutin.MyClass=DEBUG
log4j.logger.org.codelutin.MyClass.TimeLog=INFO- Since:
- 2.1
- Author:
- Benjamin Poussin - poussin@codelutin.com
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String, TimeLog.CallStat> for each method of all proxies, keep number of callprotected org.apache.commons.logging.Logloggueur used to log timeprotected longtime to trigger log time in info level (ns) (default: 1s)protected longtime to trigger log time in warn level (ns) (default: 3s) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longgetTime()return time in format acceptable forlog(long, long, String, String)method.longadd new tracelongadd new trace, stop time is automaticaly computed.longadd new trace, stop time is automaticaly computedvoidsetTimeToLogInfo(long timeToLogInfoMs) voidsetTimeToLogWarn(long timeToLogWarnMs)
-
Field Details
-
timeLog
protected org.apache.commons.logging.Log timeLogloggueur used to log time -
timeToLogInfo
protected long timeToLogInfotime to trigger log time in info level (ns) (default: 1s) -
timeToLogWarn
protected long timeToLogWarntime to trigger log time in warn level (ns) (default: 3s) -
callCount
for each method of all proxies, keep number of call
-
-
Constructor Details
-
TimeLog
protected TimeLog(org.apache.commons.logging.Log logTime) - Parameters:
logTime- log used to log time message.
-
TimeLog
- Parameters:
logName- log category used to log time message. This category must be category used to log message in classe that use this TimeLog (normaly class name). TimeLog is added at the end.
-
TimeLog
- Parameters:
logName- log category used to log time message. This category must be category used to log message in classe that use this TimeLog (normaly class name)- Since:
- 2.1
-
TimeLog
- Parameters:
logName- log category used to log time message. This category must be category used to log message in classe that use this TimeLog (normaly class name)timeToLogInfo- time in milliseconde after that we log infotimeToLogWarn- time in milliseconde after that we log warn
-
TimeLog
- Parameters:
logName- log category used to log time message. This category must be category used to log message in classe that use this TimeLog (normaly class name)timeToLogInfo- time in milliseconde after that we log infotimeToLogWarn- time in milliseconde after that we log warn
-
-
Method Details
-
setTimeToLogInfo
public void setTimeToLogInfo(long timeToLogInfoMs) - Parameters:
timeToLogInfoMs- time in milliseconde after that we log info
-
setTimeToLogWarn
public void setTimeToLogWarn(long timeToLogWarnMs) - Parameters:
timeToLogWarnMs- time in milliseconde after that we log warn
-
getCallCount
-
getTime
public static long getTime()return time in format acceptable forlog(long, long, String, String)method.- Returns:
- the current time in nanoseconds
-
log
-
log
add new trace, stop time is automaticaly computed- Parameters:
startNs- time returned bygetTime()methodmethodName- key name to store this timemsg- message to add to log- Returns:
- time used as stop time, this permit to chain many add in same method to trace time.
-
log
-