title: CDI Logging Interceptor not working in @PostConstruct
body: <p>I wanted to create a LoggingInterceptor for my current Stack:</p>
  
  <ul>
  <li>Tomcat 8.5.24</li>
  <li>Weld 2.4.5-Final</li>
  <li>JSF 2.3.3</li>
  </ul>
  
  <p>Here is the Annotation to mark methods or types for interception.</p>
  
  <pre><code>import java.lang.annotation.ElementType;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.annotation.Target;
  import javax.enterprise.util.Nonbinding;
  import javax.interceptor.InterceptorBinding;
  
  @Target({ElementType.METHOD, ElementType.TYPE})
  @Retention(RetentionPolicy.RUNTIME)
  @InterceptorBinding
  public @interface Logging {
  
      @Nonbinding
      Level value() default Level.TRACE;
  
      public enum Level {
          NONE, ALL, TRACE, DEBUG, INFO, WARN, ERROR;
      }
  }
  </code></pre>
  
  <p>Here is the Interceptor logic:</p>
  
  <pre><code>import javax.interceptor.AroundInvoke;
  import javax.interceptor.Interceptor;
  import javax.interceptor.InvocationContext;
  
  @Interceptor
  @Logging
  public class LoggingInterceptor {
  
      @AroundInvoke
      public Object interceptBusiness(final InvocationContext invocationContext) throws Exception {
          Logger log = LoggerFactory.getLogger(invocationContext.getMethod().getDeclaringClass().getName());
          log.trace("LOG start of method");
          Object result = invocationContext.proceed();
          log.trace("LOG end of method");
          return result;      
      }
  }
  </code></pre>
  
  <p>A simplified Bean:</p>
  
  <pre><code>import javax.annotation.PostConstruct;
  import javax.inject.Named;
  import javax.inject.Inject;
  import javax.faces.view.ViewScoped;
  
  @Named
  @ViewScoped
  @Logging(Level.DEBUG)
  public class ListController implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Inject
      EntityService entityService;
  
      private List&lt;Entity&gt; entityList;
  
      public List&lt;Entity&gt; getEntityList() {
          return this.entityList;
      }
  
      public void setEntityList(final List&lt;Entity&gt; entityList) {
          this.entityList= entityList;
      }
  
      public String doSomething(){
          List&lt;Entity&gt; entityList = new ArrayList&lt;&gt;();
          this.setEntityList(entityList);
          return "";
      }
  
      @PostConstruct
      public void setUp() {
          this.setEntityList(this.entityService.findAll()); 
      }
  }
  </code></pre>
  
  <p>My interceptor for business methods works like a charm if called during runtime for example when pressing a button in the jsf view which calls the <code>doSomething()</code> method.  Both the <code>doSomething()</code> and the <code>setEntityList()</code> methods will be logged. </p>
  
  <p>But all methods which are called in the <code>@PostConstruct</code> method are not logged at all. That means the <code>setEntityList()</code> method is not logged when called in the <code>@PostConstruct</code> method. </p>
  
  <p>Is there anything I can do to get the methods called from the <code>@PostConstruct</code> method to be logged. I would appreciate some help. Thanks in advance. </p>
  
  <p><strong>Update due to the answer of HRgiger:</strong></p>
  
  <p>I also tried the <code>@PostConstruct</code> method in my interceptor logic but with this method I can only log the invocation of the <code>@PostConstruct</code> itself but the methods called in the <code>@PostConstruct</code> method are not logged and that is still my main problem.</p>
  
  <pre><code>@PostConstruct
  public void interceptLifecycle(final InvocationContext invocationContext) throws Exception {
      Logger log = LoggerFactory.getLogger(invocationContext.getTarget().getClass().getSimpleName());
  
      log.info("LOG start of POSTCONSTRUCT");
      invocationContext.proceed();
      log.info("LOG end of POSTCONSTRUCT");
  }
  </code></pre>