jbuilder2005+jboss-4.0.2rc1+j2sdk1.5+log4j Development Session Bean Ii. (2)

Source: Internet
Author: User
Tags add copy log string jboss log4j
Session
Author: Junsan Jin

Date: 2005-3-30

Version: 1.0

Mailbox: junsan21@126.com; Junnef21@sohu.com

Disclaimer: I reserve all the rights of this article.





Part II: Configuring LOG4J







LOG4J is primarily a Java-generated Management Pack for log files, using logging-log4j-1.2.9 here. Decompression logging-log4j-1.2.9 compressed package, any path can be, here is D:\logging-log4j-1.2.9.







First build the project in the JBuilder and then introduce the log4j library file.



New project:







Select menu: New project...,name for trader, click Finish.







The project directory here is: E:\projects\Trader.



Copy class Library:







Create a new Lib folder under the Trader folder, and copy D:\logging-log4j-1.2.9\dist\lib\log4j-1.2.9.jar to E:\projects\Trader\lib.



To introduce a class library into engineering:







Select menu: Project〉project properties〉paths〉 Right tab required libraries > Add > tab page Archives, select E:\projects\Trader\lib, Select Log4j-1.2.9.jar in the list box on the right, all the way OK.



New Web module:







Select Menu: New〉web〉web module (WAR) 〉ok button 〉create Empty Web module〉next button, fill in name Webtrader, click the Finish button.



To increase the properties configuration file:







In the menu tree on the left of JBuilder select Webtrader〉module directory〉 Select web-inf〉 Right button new〉file, fill in log4j.properties OK.







The contents of the edited log4j.properties are as follows:







-------------------------------------------------







Log4j.properties







--------------------------------------------------







# for the general syntax the based configuration files







# Documenation of Org.apache.log4j.PropertyConfigurator.



# The root category uses the Appender called A1. Since No priority is







# specified, the root category assumes the default priority for root







# which is DEBUG in log4j. The root category is the ' only category '







# has a default priority. All other categories need is assigned a







# priority in which case they inherit their priority from the







# hierarchy.



log4j.rootcategory=, A1



# A1 is set to being a fileappender which outputs to the file







# "Factor.log". Start the server numbercruncherserver and two







# numbercruncherclients, and ask to factor two numbers







# near-simultaneously. Notice the log output from these two







# requests are logged in the file Factor.log. Nevertheless, the logs







# of these requests can still be distinguished given their distinct







# Nested diagnostic contexts.



Log4j.appender.a1=org.apache.log4j.fileappender







Log4j.appender.a1.file=${jboss.server.home.dir}/log/trader.log







Log4j.appender.a1.layout=org.apache.log4j.patternlayout



# the%x conversion specifier for NDC printing.







# log4j.appender.a1.layout.conversionpattern=%-4r%-5p [%t] (%x)-%m\n







log4j.appender.a1.layout.conversionpattern=%d [%t]%-5p%c-%m%n







log4j.appender.a1.maxfilesize=100kb



Add log4j Environment Initialization class:







Right-click in the menu tree trader.jpx〉new〉package, fill in the Com.inspiresky.trader.init, OK.







Right-click the new init package 〉new〉class, name Log4jinit.java, determine where the package is com.inspiresky.trader.init, click OK button.







The contents of the edited Log4jinit.java are as follows:







-----------------------------------------------------







Log4jinit.java







-----------------------------------------------------







Package com.inspiresky.trader.init;



Import Org.apache.log4j.PropertyConfigurator;







Import Javax.servlet.http.HttpServlet;







Import Javax.servlet.http.HttpServletRequest;







Import Javax.servlet.http.HttpServletResponse;







Import Java.io.PrintWriter;







Import java.io.IOException;







Import javax.servlet.ServletException;



public class Log4jinit extends HttpServlet {



Initialize Global Variables







public void Init () throws Servletexception {







String prefix = Getservletcontext (). Getrealpath ("/");







String file = Getinitparameter ("Log4j-init-file");







If the Log4j-init-file is isn't set, then no point in trying







if (file!= null) {







Propertyconfigurator.configure (Prefix+file);







}







}



public void Doget (HttpServletRequest req, httpservletresponse Res) {







}



Clean up resources







public void Destroy () {







}







}



To configure the Web.xml file:







In the menu tree on the left of JBuilder select Webtrader〉module directory〉web-inf, open Web.xml, <display-name>webtrader</display-name > Add the following content:







<servlet>







<servlet-name>log4j-init</servlet-name>







<servlet-class>com.inspiresky.trader.init.Log4jInit</servlet-class>







<init-param>







<param-name>log4j-init-file</param-name>







<param-value>WEB-INF/log4j.properties</param-value>







</init-param>







<load-on-startup>1</load-on-startup>







</servlet>



OK, so far our log4j have been able to use the normal. (To be continued)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.