HPSC 中的日志可以分为性能日志和错误堆栈日志
性能日志用spring的AOP来控制所需要监控的bean方法执行多少时间
错误日志是用来解决代码中的bug的
配置 BeanNameAutoProxyCreator
性能日志用spring的AOP来控制所需要监控的bean方法执行多少时间
错误日志是用来解决代码中的bug的
配置 BeanNameAutoProxyCreator
<bean id="performaceLog" class="com.tristan.web.utils.PerformaceLog"></bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>userService</value>
<value>userDAO</value>
</list>
</property>
<property name="interceptorNames">
<list>
<idref bean="performaceLog"/>
</list>
</property>
<property name="proxyTargetClass" value="true" />
</bean>
public class PerformaceLog implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String className = invocation.getMethod().getDeclaringClass().getName();
String methodName = invocation.getMethod().getName();
long begin = System.currentTimeMillis();
Object result = invocation.proceed();
long end = System.currentTimeMillis(); // 测试结束时间
System.out.println("(" + className + "." + methodName + ") 操作所需时间:" + (end - begin) + " 毫秒"); // 打印使用时间
return result;
}
}