拦截器定义
public class LogInterceptor extends AbstractInterceptor {
private static final Logger log = Logger.getLogger(LogInterceptor.class);
@Override
public String intercept(ActionInvocation invocation) throws Exception {
final String className = invocation.getAction().getClass().getName();
final String methodName = invocation.getProxy().getMethod();
final long start = System.currentTimeMillis();
log.debug(StringUtil.getLine() + StringUtil.getLine() + StringUtil.getLine() + StringUtil.getLine()
+ "==========" + className + "." + methodName
+ "==========");
try {
String result = invocation.invoke();
return result;
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
long time = System.currentTimeMillis() - start;
if (time > 1000) {
InterceptorLogService.saveInterceptorLog(time, className, methodName);
}
}
}
}
配置
<package name="system" namespace="/system" extends="struts-default">
<interceptors>
<interceptor name="log" class="crm.framework.web.interceptor.LogInterceptor" />
<interceptor-stack name="systemStrack">
<interceptor-ref name="log" />
</interceptor-stack>
</interceptors>
</package>