First, one has to double click the project, so that the window of the libraries appears, in order to add the Log4j jar library.
Second, navigate to C:\...\Model\src to create the log4j.properties file:
# **Set root logger level to DEBUG and its only appender to A.
log4j.rootLogger=DEBUG, A
# ***** A is set to be a ConsoleAppender.
log4j.appender.A=org.apache.log4j.ConsoleAppender
# ***** A uses PatternLayout.
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
Finally, if one 'd like to use log4j within a stateful EJB class, the source code is similar:
...
import org.apache.log4j.Logger;
@Stateful(name = "PlaceOrder", mappedName = "ejb3inaction-Model-PlaceOrder")
@Remote
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class PlaceOrderBean implements PlaceOrder {
Logger logger =Logger.getLogger(this.getClass().getSimpleName());
...
@Remove
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public Long confirmOrder() {
...
em.persist(order);
if (logger.isDebugEnabled())
logger.debug("******************Order confirmed!**************");
return order.getOrderId();
}
...
}
Thus, one gets the following log output from the integrated Weblogic server:
Run startup time: 9656 ms.
[Application ejb3inaction deployed to Server Instance IntegratedWebLogicServer]
0 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO PlaceOrder_i7ibfi_Impl - ******************Order confirmed!**************
Finally, if you need more tips about appenders:
http://www.mobilefish.com/developer/log4j/log4j_quickguide_appenders.html
No comments:
Post a Comment