title: Placing log information inside a method: Using AspectJ , Spring
body: <p>I am new to AOP and I came to know that it helps in separating <code>crosscutting</code> concerns, and seems to be a good feature which adds charm to OOPs programming.</p>
  
  <p>As always, the classical example which I found was the "logging", in which using AOP, the logging can be done using AOP.</p>
  
  <h1>Consider this situation:</h1>
  
  <pre><code>public void doSomething(String name, Object someObj) {
  
     logger.info("Just entered doSomething() method));
     int result;
  
     // Some complex code
  
     if(result != 0) {
         logger.severe("There is some issues, fix it...");
         // some other code
    }
  
   logger.trace("Did some more work, value is " +value);
  
   // Other business code..
  
  logger.info("Returning from method...");
  } 
  </code></pre>
  
  <p>Now, referring to online documentation/tutorial, the use-case of "logging advice" is that we can remove the logging code from the code and "logging advice" will do the logging, for example during entering , returning of method, using annotations.</p>
  
  <p>In above example, I agree that using @Before, @After "advice" can help for entering, returning of the method call.</p>
  
  <p>I am confused in how AOP helps in for the loggers which are withing inside the method, and ideally can be used anywhere, where we capture information at some point of time.</p>
  
  <p>I referred to <a href="https://stackoverflow.com/questions/15465608/spring-aop-capturing-of-logs-inside-a-method">this SO question</a> , but didn't get any clarity in how AOP can help situations like this.</p>
  
  <p>Can anyone help me understand this?</p>