public class TimeLog extends Object
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
CallAnalyse
Modifier and Type | Class and Description |
---|---|
static class |
TimeLog.CallStat |
Modifier and Type | Field and Description |
---|---|
protected Map<String,TimeLog.CallStat> |
callCount
for each method of all proxies, keep number of call
|
protected org.apache.commons.logging.Log |
timeLog
loggueur used to log time
|
protected long |
timeToLogInfo
time to trigger log time in info level (ns) (default: 1s)
|
protected long |
timeToLogWarn
time to trigger log time in warn level (ns) (default: 3s)
|
Modifier | Constructor and Description |
---|---|
|
TimeLog(Class<?> logName) |
|
TimeLog(Class<?> logName,
long timeToLogInfo,
long timeToLogWarn) |
protected |
TimeLog(org.apache.commons.logging.Log logTime) |
|
TimeLog(String logName) |
|
TimeLog(String logName,
long timeToLogInfo,
long timeToLogWarn) |
Modifier and Type | Method and Description |
---|---|
Map<String,TimeLog.CallStat> |
getCallCount() |
static long |
getTime()
return time in format acceptable for
log(long, long, String, String) method. |
long |
log(long startNs,
long stopNs,
String methodName,
String msg)
add new trace
|
long |
log(long startNs,
String methodName)
add new trace, stop time is automaticaly computed.
|
long |
log(long startNs,
String methodName,
String msg)
add new trace, stop time is automaticaly computed
|
void |
setTimeToLogInfo(long timeToLogInfoMs) |
void |
setTimeToLogWarn(long timeToLogWarnMs) |
protected org.apache.commons.logging.Log timeLog
protected long timeToLogInfo
protected long timeToLogWarn
protected Map<String,TimeLog.CallStat> callCount
protected TimeLog(org.apache.commons.logging.Log logTime)
logTime
- log used to log time message.public TimeLog(String logName)
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.public TimeLog(Class<?> logName)
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)public TimeLog(String logName, long timeToLogInfo, long timeToLogWarn)
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 warnpublic TimeLog(Class<?> logName, long timeToLogInfo, long timeToLogWarn)
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 warnpublic void setTimeToLogInfo(long timeToLogInfoMs)
timeToLogInfoMs
- time in milliseconde after that we log infopublic void setTimeToLogWarn(long timeToLogWarnMs)
timeToLogWarnMs
- time in milliseconde after that we log warnpublic Map<String,TimeLog.CallStat> getCallCount()
public static long getTime()
log(long, long, String, String)
method.public long log(long startNs, String methodName)
startNs
- time returned by getTime()
methodmethodName
- key name to store this timepublic long log(long startNs, String methodName, String msg)
startNs
- time returned by getTime()
methodmethodName
- key name to store this timemsg
- message to add to logCopyright © 2004–2020 CodeLutin. All rights reserved.