|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.developersupport.LoggingProxyFactory
This factory produces dynamic proxies
that can log and delegate
all method calls to the object for which they are proxying.
After instantiating a factory instance, you can configure it via methods
like setLogger(String)
and setLevel(String)
. Once
configured, the factory can produce, via its newLoggingProxy(Object,
Class)
method, dynamic proxy objects implementing the required
interface.
Constructor Summary | |
LoggingProxyFactory()
|
Method Summary | |
void |
enableStackTraces()
Call this method to enable the logging of a stack trace for each intercepted method call. |
Object |
newLoggingProxy(Object proxiedObject,
Class iface)
This is equivalent to . |
Object |
newLoggingProxy(Object proxiedObject,
Class iface,
boolean configurable)
Returns an object that implements the iface and LoggingProxy interfaces. |
void |
setLevel(String level)
Sets the logging level for the logger. |
void |
setLogger(String logger)
Sets the logger that will be used to log method calls. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public LoggingProxyFactory()
Method Detail |
public void setLogger(String logger)
setLogger
in interface LoggerConfigurator
setLevel(String)
public void setLevel(String level)
Sets the logging level for the logger. If you don't ever call this
method to specify the logging level explicitly, it will default to
"debug"
. If you specify an invalid logging level, the
default value of "debug"
will be substituted silently.
setLevel
in interface LoggerConfigurator
setLogger(String)
public void enableStackTraces()
enableStackTraces
in interface LoggerConfigurator
public Object newLoggingProxy(Object proxiedObject, Class iface, boolean configurable)
iface
and LoggingProxy
interfaces.
The object works by delegating all method calls to
proxiedObject
. Method calls are logged on entry using the
logger specified via setLogger(String)
. If no logger was
specified, Logger.getLogger(LoggingProxyFactory.class)
is
used. Example:
protected void service(HttpServletRequest req, HttpServletResponse resp) { LoggingProxyFactory factory = new LoggingProxyFactory(); factory.enableStackTraces(); factory.setLevel("info"); HttpServletRequest reqProxy = (HttpServletRequest) factory.newLoggingProxy(req, HttpServletRequest.class, true); doStuff((HttpServletRequest) reqProxy, resp) } private void doStuff(HttpServletRequest req, HttpServletResponse resp) { // ... if ( Proxy.isProxyClass(req.getClass()) ) { LoggingProxy proxy = (LoggingProxy) req; HttpServletRequest realReq = (HttpServletRequest) req.getProxiedObject(); // do stuff with the original, unwrapped request. } }
This allows you to track all calls to the HTTP request object that are
made in your program during the execution of the service(req,
resp)
.
proxiedObject
- the proxied objectiface
- the interface to be implemented by the returned dynamic proxyconfigurable
- if true
, the returned object will also
implement the LoggingProxy
interface. Note that requiring the
logging proxy to implement this additional interface may cause an IllegalArgumentException
due to the fact the specified interface is not
accessible to the classloader with which proxiedObject
was
instantiated. See also newLoggingProxy(Object, Class)
.
iface
. The
returned object will be created by the same classloader with which
proxiedObject
was created.newLoggingProxy(Object, Class)
public Object newLoggingProxy(Object proxiedObject, Class iface)
newLoggingProxy(proxiedObject, iface, false)
. In other
words, the returned proxy does not implement the LoggingProxy
interface.
newLoggingProxy(Object, Class, boolean)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |