Download
Http://jakarta.apache.org/log4j/docs/download.html2. Add log4j_home / dist / lib / log4j-version.jar to the project's Required Libraries. 3. Use: package util; import java.net.ull; import org.apache.log4j.logger; import org.apache.log4j.propertyConfigurator;
Public class log4j {public static logger logger = logger.getlogger (util.log4j.class.getname ());
// Call a configuration file (log does not wrap output) public static void ConfigLog () {String resource = "/util/ConfigLog.properties"; URL configFileResource = util.Log4j.class.getResource (resource); PropertyConfigurator.configure (configFileResource );} // call the two profiles (log wrap output) public static void ConfigLog_ln () {String resource = "/util/ConfigLog_ln.properties"; URL configFileResource = util.Log4j.class.getResource (resource); PropertyConfigurator.configure (configFileResource);}} in yet built package util ConfigLog.properties and ConfigLog_ln.properties profile # ConfigLog.properties # set logger and level log4j.rootCategory = DEBUG, R # output to a file log4j.appender.R = org.apache .log4j.fileappender # output log file name (stored in the root directory of the project) log4j.Appender.r.file = log.txt # file format is a custom mode (4 optional) log4j.Appender.r. layout = org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern =% m # ConfigLog_ln.properties # set logger and level log4j.rootCategory = DEBUG, R # output to a file log4j.appender.R = org.apache .log4j.fileAppender # output log file name (stored in the root directory of the project) log4j.Appender.r.file = Log.txt # file format is a custom mode (4 optional) log4j.Appender.r.Layout = org.apache.log4j.patternLayout log4j.Appender.r.Layout.conversionPattern =% m% N can be used The import util.log4j is called as follows; log4j.configlog (); log4j.logger.debug ("hello,"); log4j.logger.info ("My Name is Vincent Casularm."); Log4j.configlog_ln (); log4j. Logger.debug ("Hello,"); log4j.logger.info ("My Name is Vincent Casularm."); outputs the following Hello, My Name is Vincent Casularm.hello, My Name is Vincent Casularm. Note: If you use the * .html file storage log, even if the% N is used, it will be displayed continuously, you need to manually add a chamber
p>.
Here is just a simple example. You can refer to Log4J for your Concise manual (English) http://jakarta.apache.org/log4j/docs/manual.html