Results 1 to 2 of 2

Thread: Is Spring AOP really an effective strategy for logging?

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Default Is Spring AOP really an effective strategy for logging?

    I’m trying to set up a logging strategy for my company with the idea of making it as simple for the developers as possible. We could possibly have hundreds of classes that are in our application and while most likely, all will not need to log, I would like the opportunity to do so.

    My plan was to monitor every time the following method was called from possibly a Ilogging Interface:

    writeMessage(String level, String msg)

    Is there a way to monitor this writeMessage call without having to wire the hundreds of apps within my xml? I have seen proxies used but that would seem to just blow up my xml, not mention having to know every single class that needs a proxy. Is there a way to minimize the wiring in my Spring xml while still being able to monitor that message call for all hundred apps?

    Code:
    public class SomeApp1 implements ILoggingService {
    
        public void otherSomething() {
            writeMessage("Info", "OtherClass wants to log");
        }
    
        @Override
        public void writeMessage(String level, String message) {
            // TODO Auto-generated method stub
            
        }
    }

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Have you read the reference guide, especially the section on AOP? Also your setup isn't going to work as spring by default uses proxies which means ONLY external method calls are intercepted not INTERNAL method calls. So you probably want to use AspectJ to do either load time or compile time weaving (load time is possible with spring).

    Applying the aspect is as simple as writing a single pointcut and it will be applied, in total about 3 to 5 lines of xml. No more no less. However again I suggest a read of the reference guide.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •