T
- the type of class to be instrumentedpublic class LoggingInvocationHandler<T>
extends java.lang.Object
implements java.lang.reflect.InvocationHandler
LoggingInvocationHandler
class is useful for instrumenting
a class to log all method invocations with the accompanying arguments and
return value.Constructor and Description |
---|
LoggingInvocationHandler(java.lang.reflect.InvocationHandler decorated,
java.util.logging.Logger logger)
Create a new
LoggingInvocationHandler for the given
InvocationHandler (to be decorated) and logger. |
LoggingInvocationHandler(T delegate,
java.util.logging.Logger logger)
Create a new
LoggingInvocationHandler for the given delegate
and logger. |
Modifier and Type | Method and Description |
---|---|
java.util.logging.Level |
getLevel() |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args) |
void |
setIncludeStackTrace(boolean includeStack)
Set whether or not log statements should include the stack trace (default
is
false ). |
void |
setLevel(java.util.logging.Level logLevel)
Set the
Level at which the log statements will be logged. |
void |
setMethodFilter(Filter<java.lang.reflect.Method> filter)
Use the given filter to determine which methods should be logged.
|
void |
setMethodNames(java.lang.String... methodNames)
Set the name(s) of the method(s) which should be logged.
|
public LoggingInvocationHandler(T delegate, java.util.logging.Logger logger)
LoggingInvocationHandler
for the given delegate
and logger.delegate
- the delegate to which all method invocations will be
forwardedlogger
- the logger to which all log statements will be sentpublic LoggingInvocationHandler(java.lang.reflect.InvocationHandler decorated, java.util.logging.Logger logger)
LoggingInvocationHandler
for the given
InvocationHandler
(to be decorated) and logger.decorated
- another InvocationHandler
to which all method
invocations will be forwardedlogger
- the Logger
to which all log statements will be
forwardedjava.lang.IllegalArgumentException
- if either argument is null
public final java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
public void setLevel(java.util.logging.Level logLevel)
Level
at which the log statements will be logged.logLevel
- public java.util.logging.Level getLevel()
public void setIncludeStackTrace(boolean includeStack)
false
).includeStack
- true
if log statements should include the
stack trace, false
(default) otherwisepublic void setMethodFilter(Filter<java.lang.reflect.Method> filter)
filter
- public void setMethodNames(java.lang.String... methodNames)
methodNames
-