[java]log4j

Source: Internet
Author: User

How to log logs using log4j First step: Add the Jar file project used by log4j in the project? Properties: Popup Project's Properties window Java build path? Add an external jar: Pop-up the window of the selection jar to find the log4j-1.2. X.jar, and confirm back to the project's Properties window, click OK Second Step: Create Log4j.properties File Select the project you want to use log4j? Right-click src? Other: Pop-up Selection wizard window in the Select Wizard window, select General? file? Next: Pop Up the new File window in the New File window, enter the file name Log4j.properties? Finish: Create a job Finish step three: use log4j to log informationImportOrg.apache.log4j.Logger; Public classteacherlog4j { Public Static voidMain (string[] args) {Teacher Teacher=NewTeacher (); Logger Logger= Logger.getlogger (teacherlog4j.class); Try{logger.debug ("Sets the number of the instructor. "); Teacher.setid ("088"); } Catch(IllegalArgumentException ex) {Logger.info (Ex.getmessage ());} }} Fourth: Write the Log4j.properties file, configure the log information # # # to output the log information to the console # # #log4j. Appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=Org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{yyyy-mm-dd HH:mm:ss}%m%n### output log information to file: Accp.log # # #log4j. Appender.file=Org.apache.log4j.FileAppenderlog4j.appender.file.File=Accp.loglog4j.appender.file.layout=Org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d{yyyy-mm-dd HH:mm:ss}%l%m%n### Set the priority level, and the output source # # #log4j. Rootlogger=debug, stdout, file

[java]log4j

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.