SeamFramework.orgCommunity Documentation

Chapter 19. CDI extensions available as part of Weld

19.1. Weld Logger

Important

These modules are usable on any JSR-299 implementation, not just Weld!

Adding logging to your application is now even easier with simple injection of a logger object into any CDI bean. Simply create an injection point of type org.slf4j.Logger and an appropriate logger object will be injected into any instance of the bean.

import org.slf4j.Logger;

import javax.inject.Inject;
public class Checkout {
   private @Inject Logger log;
   public void invoiceItems() {
      ShoppingCart cart;
      ...
      log.debug("Items invoiced for {}", cart);
   }
}

The example shows how objects can be interpolated into a message. If you use this approach, you do not need to surround a call to the logger with a condition like if ( log.isDebugEnabled() ) to avoid string concatenation.