I have implemented spring AOP to audit my methods(which would read method parameters and arguments). I am not sure how to audit variables which have been declared inside a method. In below example, I want to audit "c" and "name" variables.
public void method1(int a, int b){
int c = a+b;
String user= "test";
}
NOTE: I need both variable name(i.e "c") and it's value( let's say a and b are 3 and 4 respectively) i.e 7 and similarly variable name(i.e "user") and it's value(i.e "test") for my auditing
In my application, let's say I have method called "process(Object... values) / process(Map)" which would take either "varargs" or "map" as it's argument(process() method definition is upto us). So, we need to pass the variables that we want to audit to this process() method.
My approach:
public void method1(int a, int b){
int c = a+b;
String user= "test";
// logic to send variables to process method
Map<String, Object> myMap = new HashMap<>();
myMap.put("c",c);
myMap.put("user",name);
process(myMap);
}
The problem with this approach is that developer has to create the map and populate values each time.
Please suggest me if we could do this in an efficient way. Thanks in advance.