extensions.xml 2.07 KB
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"  [ ]>
<chapter id="extensions">

   <!-- TODO turn this into an extensions primer and have a separate guide for writing
   extensions to CDI that perhaps go into detail about the Weld build -->

   <title>CDI extensions available as part of Weld</title>
   
   <important>
      <para>
         These modules are usable on any JSR-299 implementation, not just Weld!
      </para>
   </important>

   <section>
      <title>Weld Logger</title>
      
      <para>
         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 <literal>org.slf4j.Logger</literal> and an appropriate logger 
         object will be injected into any instance of the bean.
      </para>

      <programlisting role="JAVA"><![CDATA[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);
   }
}]]></programlisting>

      <para>
         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 <literal>if ( log.isDebugEnabled() )</literal> to
         avoid string concatenation.
      </para>
      
      <note>
	      <para>
            You can add Weld logging to your project by including weld-logger.jar, sl4j-api.jar and sl4j-jdk14.jar to
            your project. Alternatively, express a dependency on the <literal>org.jboss.weld:weld-logger</literal> 
            Maven artifact. 
	      </para>
	      <para>
            If you are using Weld as your JSR-299 implementation, there's no need to include sl4j as it's already
            included (and used internally).
	      </para>
      </note>

   </section>

   <!-- TODO surely we must have other extensions -->
   
<!--
vim:et:ts=3:sw=3:tw=120
-->
</chapter>