John Smith (WHO) create user (WHAT-1), user ID is 100 (WHAT-2)
Using AOP, I can at least get WHAT-1 information by getting the method
name.
If you have control about the environment / requirements you might want to go for a true aspect oriented solution and try out AspectJ. Just advice the service interfaces forumlating advices on a single method base, so you can easily investigate the parameters and formulate usefull logging informations (also using AspectJ you can use polymorphism for the logging aspects).
Another idea would be using the Command/Action pattern and let the command implement an interface making it possible for the command to describe itself. (see the second post in this thread).
[edit]
Please take a look at the BeforeMethodAdvice (or AfterMethodAdvice) within the AOP framework. It features the following abstract method:
void before(Method method, Object[] args, Object target) throws Throwable;
So you can catch the method being called, the WHO information and also the parameters. So you don't need to switch to AspectJ to just investigate the parameters also.
So for your task it might look like:
Code:
void before(Method method, Object[] args, Object target) {
if(isAddUserMethod(method))
log("The user '"+getUser()+"' added a new user with the id "+args[0]+" and the name '"+args[1]+"'");
}
This looks ugly and can be improved for readabilty for sure but I think you get the meaning.
[/edit]
Cheers,
Martin (Kersten)