Announcement Announcement Module
Collapse
No announcement yet.
Is Spring AOP really an effective strategy for logging? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X