View RSS Feed

My Java Tips

Log method entry and exit

Rate this Entry
by , 10-30-2011 at 05:39 PM (1425 Views)
The typical approach we use in Java is given below:

Java Code:
public String myMethod(String param)

{

  if (LOG.isDebugEnabled())

    LOG.debug("myMethod(" + param + ")");

 

String result = // . . .

if (LOG.isDebugEnabled())

  LOG.debug("myMethod() returns " + result);

return result;

}


This will work but it doesn't do a consistent job when a method has multiple return points. It also creates many more branch points within the code. Finally, it doesn't report on exceptions thrown from within the method.

HiveMind provides a better approach to this. Let HiveMind add a logging interceptor to your service. It will consistently log method entry and exit, and log any exceptions thrown by the method.

The following descriptor snippet defines a service, provides a core service implementation (using <create-instance>), and adds method logging (using <interceptor>):</interceptor></create-instance>

<service-point id="MyService" interface="com.myco.MyServiceInterface">

<create-instance class="com.myco.impl.MyServiceImpl">

<interceptor service-id="hivemind.LoggingInterceptor"></interceptor>

</create-instance></service-point></pre>

Submit "Log method entry and exit" to Facebook Submit "Log method entry and exit" to Digg Submit "Log method entry and exit" to del.icio.us Submit "Log method entry and exit" to StumbleUpon Submit "Log method entry and exit" to Google

Tags: None Add / Edit Tags
Categories
HiveMind , XML

Comments