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