0

I'm building a Spring web application. Using Spring AOP's aspect to do audit logging.

I've got business class with methods like the following and i want to audit log in certain cases

  • during method execution
  • after method returns

    @Aspect  
    public class MyBusinessClass {...
    
    public void registerUser() {  
           // do some business logic here...  
          userId = // userService.saveUser(...).getId(); // etc...  
          if(successful) {  
              // then send Email notification  
             audit.log(userId, "success sending email notification"... some other params);  
          else {
              audit.log(userId, "fail to send email notification"...);  
          }  
          //do some more logic before returning method  
          audit.log(userId,"successfully registered user...." ...);  
          ..// method returns   
          }
    

I've already got Aspects defined in a separate class.

I'm having problems because all the common simple examples i've seen on here and on other articles seemed to be very simple. For example, they work easily because the most complicated i've seen only go as far as extracting method params into the aspect's advice..

But my problem here is that i wan't to somehow not just extract local variables into the Aspect's advice but do the audit logging more than once and also based on certain conditions.

Don't get me wrong, we've already got Log4j logging to log to file in the same places but we also require to do these audit logging to DB too.

I just want to know what's the solution to achieve what i want to do in a high level.

Apologies for the slightly poor code formatting... (it's mostly pseudocode). I just can't get this code formatting to work on StackOverflow. It's much easier on Github markdown.

SoftwareDeveloper
  • 1,094
  • 2
  • 15
  • 26
  • 1
    I've read your question twice and still don't know what you want to do. You may want to be more specific, possibly with a (pseudo-)code example of what it is you are trying to do. – sheltem Nov 13 '15 at 12:15
  • I agree that the question is unclear. If you are indeed a software developer as your nickname implies, you should be able to explain better or provide an [SSCCE](http://sscce.org/) in order to describe your situation. You cannot complain about other solutions being "too simple" and at the same time just provide some over-simplified pesudo code. Your question has received two close votes already, so please improve it before it will be closed altogether. – kriegaex Nov 21 '15 at 11:48
  • hm. apologies. i think now i don't need an answer to this as this problem is no longer valid for me. please go ahead and close. thanks – SoftwareDeveloper Nov 22 '15 at 11:34

0 Answers0