Intercept write action and generate user log
I want to log every user action that change domain in my web application. when user try to create, update, delete some data the action must be save in to the user log. but when user action is list, generate report. it doesn't need to log.
I my current program, I write service log. and call that service log to each action method (performCreate, performUpdate, performDelete)
Is there any way to create single class to write user log that intercept all write action performed ? 开发者_开发技巧
Edit: I use Struts 1.x
You can use Aspect Oriented Programming, a simple solution in aspectj looks like this:
public aspect Logger {
pointcut writeActions():
execution (* *.perform*(..));
void before(): writeActions(){
// log the action
}
}
you also can access the method parameters, get the return value and execute code before or after method execution.
精彩评论