title: how to log with Spring AOP and SPring boot
body: <p>i use the same class LoggingAspect as in this example tutorial <a href="https://www.javaguides.net/2019/05/spring-boot-spring-aop-logging-example-tutorial.html" rel="nofollow noreferrer">https://www.javaguides.net/2019/05/spring-boot-spring-aop-logging-example-tutorial.html</a>, but when i call a controller methode i get only those messages on console </p>
  
  <pre><code>11-05-2020 13:30:27.742 [http-nio-8080-exec-7] INFO  o.a.c.c.C.[.[localhost].[/appged].log - Initializing Spring DispatcherServlet 'dispatcherServlet'
  11-05-2020 13:30:27.742 [http-nio-8080-exec-7] INFO  o.s.web.servlet.DispatcherServlet.initServletBean - Initializing Servlet 'dispatcherServlet'
  11-05-2020 13:30:27.771 [http-nio-8080-exec-7] INFO  o.s.web.servlet.DispatcherServlet.initServletBean - Completed initialization in 29 ms
  </code></pre>
  
  <p>la classe le Logging Aspect :
          package com.app.ged.api.aspect;</p>
  
  <pre><code>import java.util.Arrays;
  
  import org.aspectj.lang.JoinPoint;
  import org.aspectj.lang.ProceedingJoinPoint;
  import org.aspectj.lang.annotation.AfterThrowing;
  import org.aspectj.lang.annotation.Around;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Pointcut;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Component;
  
  /**
   * Aspect for logging execution of service and repository Spring components.
   * 
   *
   */
  @Aspect
  @Component
  public class LoggingAspect {
  
      private final Logger log = LoggerFactory.getLogger(this.getClass());
  
      /**
       * Pointcut that matches all repositories, services and Web REST endpoints.
       */
      @Pointcut("within(@org.springframework.stereotype.Repository *)" +
          " || within(@org.springframework.stereotype.Service *)" +
          " || within(@org.springframework.web.bind.annotation.RestController *)")
      public void springBeanPointcut() {
          // Method is empty as this is just a Pointcut, the implementations are in the advices.
      }
  
      /**
       * Pointcut that matches all Spring beans in the application's main packages.
       */
      @Pointcut("within(com.app.ged.api.repository.*)"+
          " || within(com.app.ged.api.service.*)"+
          " || within(com.app.ged.api.controller.*)")
      public void applicationPackagePointcut() {
          // Method is empty as this is just a Pointcut, the implementations are in the advices.
      }
  
      /**
       * Advice that logs methods throwing exceptions.
       *
       * @param joinPoint join point for advice
       * @param e exception
       */
      @AfterThrowing(pointcut = "applicationPackagePointcut() &amp;&amp; springBeanPointcut()", throwing = "e")
      public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
              log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                  joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL");
      }
  
      /**
       * Advice that logs when a method is entered and exited.
       *
       * @param joinPoint join point for advice
       * @return result
       * @throws Throwable throws IllegalArgumentException
       */
      @Around("applicationPackagePointcut() &amp;&amp; springBeanPointcut()")
      public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
          if (log.isDebugEnabled()) {
              log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                  joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
          }
          try {
              Object result = joinPoint.proceed();
              if (log.isDebugEnabled()) {
                  log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                      joinPoint.getSignature().getName(), result);
              }
              return result;
          } catch (IllegalArgumentException e) {
              log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                  joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
              throw e;
          }
      }
  
  
  }
  </code></pre>
  
  <p>my logback-spring.xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
  
    &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;
            %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n
        &lt;/pattern&gt;
      &lt;/encoder&gt;
    &lt;/appender&gt;
  
    &lt;appender name="SAVE-TO-FILE" class="ch.qos.logback.core.FileAppender"&gt;
      &lt;file&gt;${LOG_PATH}/log-appGed.log&lt;/file&gt;
      &lt;encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"&gt;
        &lt;Pattern&gt;
          %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n
        &lt;/Pattern&gt;
      &lt;/encoder&gt;
    &lt;/appender&gt;
  
    &lt;springProfile name="pc"&gt;
      &lt;root level="info"&gt;
        &lt;appender-ref ref="STDOUT"/&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/root&gt;
       &lt;logger name="com.app.ged.api.controller" additivity="false" level="debug"&gt;
        &lt;appender-ref ref="STDOUT"/&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/logger&gt;
      &lt;logger name="com.app.ged.api.service" additivity="false" level="debug"&gt;
        &lt;appender-ref ref="STDOUT"/&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/logger&gt;
    &lt;/springProfile&gt;
  
    &lt;springProfile name="dev"&gt;
      &lt;root level="info"&gt;
        &lt;appender-ref ref="STDOUT"/&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/root&gt;
      &lt;logger name="com.app.api.service" additivity="false" level="debug"&gt;
        &lt;appender-ref ref="STDOUT"/&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/logger&gt;
    &lt;/springProfile&gt;
  
    &lt;springProfile name="prod"&gt;
      &lt;root level="info"&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/root&gt;
      &lt;logger name="com.app.ged.api.service" additivity="false" level="error"&gt;
        &lt;appender-ref ref="SAVE-TO-FILE"/&gt;
      &lt;/logger&gt;
    &lt;/springProfile&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>application.properties </p>
  
  <pre><code>#logging 
  spring.profiles.active=pc
  logging.path=C:/logs
  </code></pre>