public final class PerfLogger extends Object
Usage:
The above will do nothing if the log level for the logger passed to PerfLogger at construction time is not DEBUG or TRACE - otherwise start() will return the current time in milliseconds and end will issue a log statement if the time between start and end was bigger than 1 ms, and it will pass the parameters to the log statement. The idea is to keep up performance at max possible if the log level is INFO or higher - but to allow some meaningful logging if at DEBUG or TRACe. The difference between DEBUG and TRACE is that TRACE will log start too (if a log message is passed to start) and it will always log the end - whereas in case of DEBUG the start will never be logged and the end will only be logged if the time is bigger than what's passed to end.
Constructor and Description |
---|
PerfLogger(org.slf4j.Logger delegate)
Create a new PerfLogger that shall use the given Logger object for logging
|
Modifier and Type | Method and Description |
---|---|
void |
end(long start,
long logAtDebugIfSlowerThanMs,
String logMessagePrefix,
Object... arguments)
Returns quickly if log level is not DEBUG or TRACE - if it is DEBUG
and the difference between now and the provided 'start' is bigger (slower)
than 'logAtDebugIfSlowerThanMs', then a log.debug is emitted, if at
TRACE then a log.trace is always emitted (independent of time measured).
|
void |
end(long start,
long logAtDebugIfSlowerThanMs,
String logMessagePrefix,
Object arg1)
Returns quickly if log level is not DEBUG or TRACE - if it is DEBUG
and the difference between now and the provided 'start' is bigger (slower)
than 'logAtDebugIfSlowerThanMs', then a log.debug is emitted, if at
TRACE then a log.trace is always emitted (independent of time measured).
|
void |
end(long start,
long logAtDebugIfSlowerThanMs,
String logMessagePrefix,
Object arg1,
Object arg2)
Returns quickly if log level is not DEBUG or TRACE - if it is DEBUG
and the difference between now and the provided 'start' is bigger (slower)
than 'logAtDebugIfSlowerThanMs', then a log.debug is emitted, if at
TRACE then a log.trace is always emitted (independent of time measured).
|
boolean |
isDebugEnabled()
Whether or not the delegate has log level DEBUG configured
|
boolean |
isTraceEnabled()
Whether or not the delegate has log level TRACE configured
|
long |
start()
Returns quickly if log level is not DEBUG or TRACE - otherwise just
returns the current time in millis.
|
long |
start(String traceMsgOrNull)
Returns quickly if log level is not DEBUG or TRACE - if it is DEBUG, then
just returns the current time in millis, if it is TRACE, then log the
given message and also return the current time in millis.
|
public PerfLogger(org.slf4j.Logger delegate)
public final long start()
public final long start(String traceMsgOrNull)
traceMsgOrNull
- the message to log if log level is TRACE - or null if no
message should be logged (even on TRACE level)public final void end(long start, long logAtDebugIfSlowerThanMs, String logMessagePrefix, Object arg1)
Note that this method exists for performance optimization only (compared to the other end() method with a vararg.
start
- the start time with which 'now' should be comparedlogAtDebugIfSlowerThanMs
- the number of milliseconds that must
be surpassed to issue a log.debug (if log level is DEBUG)logMessagePrefix
- the log message 'prefix' - to which the given
argument will be passed, plus the measured time difference in the format
'[took x ms']arg1
- the argument which is to be passed to the log statementpublic final void end(long start, long logAtDebugIfSlowerThanMs, String logMessagePrefix, Object arg1, Object arg2)
Note that this method exists for performance optimization only (compared to the other end() method with a vararg.
start
- the start time with which 'now' should be comparedlogAtDebugIfSlowerThanMs
- the number of milliseconds that must
be surpassed to issue a log.debug (if log level is DEBUG)logMessagePrefix
- the log message 'prefix' - to which the given
arguments will be passed, plus the measured time difference in the format
'[took x ms']arg1
- the first argument which is to be passed to the log statementarg2
- the second argument which is to be passed to the log statementpublic void end(long start, long logAtDebugIfSlowerThanMs, String logMessagePrefix, Object... arguments)
start
- the start time with which 'now' should be comparedlogAtDebugIfSlowerThanMs
- the number of milliseconds that must
be surpassed to issue a log.debug (if log level is DEBUG)logMessagePrefix
- the log message 'prefix' - to which the given
arguments will be passed, plus the measured time difference in the format
'[took x ms']arguments
- the arguments which is to be passed to the log statementpublic final boolean isDebugEnabled()
public final boolean isTraceEnabled()
"Copyright © 2006 - 2015 Adobe Systems Incorporated. All Rights Reserved"