SeamFramework.orgCommunity Documentation
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 annotate a org.jboss.weld.log.Log
type member with the
@Logger qualifier annotation and an appropriate logger object will be injected into any
instance of the bean.
import org.jboss.weld.annotation.Logger;
import org.jboss.weld.log.Log;
public class Checkout {
private @Inject @Logger Log log;
public void invoiceItems() {
ShoppingCart cart;
...
log.debug("Items invoiced for {0}", cart);
}
}
The example shows how objects can be interpolated into a message. This interpolation is done using
java.text.MessageFormat, so see the JavaDoc for that class for more details. In this case,
the ShoppingCart
should have implemented the toString() method to
produce a human readable value that is meaningful in messages. Normally, this call would have involved
evaluating cart.toString() with String concatenation to produce a single String argument. Thus it was necessary
to surround the call with an if-statement using the condition log.isDebugEnabled() to
avoid the expensive String concatenation if the message was not actually going to be used. However, when using
@Logger
-injected logging, the conditional test can be left out since the object arguments
are not evaluated unless the message is going to be logged.
You can add the Weld Logger to your project by including weld-logger.jar, sl4j-api.jar and sl4j-jdk14.jar to
your project. Alternatively, express a dependency on the org.jboss.weld:weld-logger
Maven
artifact.
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).