1 Import log4j, I this version is 1.2.17 own choose version * * Don't tell me not to import
2 Path Bottle
3 Create a directory file with SRC named log4.properties
4 The contents of the file are, directly copied,
1 # # \u8bbe\u7f6e###2 Log4j.rootlogger = Debug,stdout,d,e3 4 # # # \u8f93\u51fa\u4fe1\u606f\u5230\u63a7\u5236\u62ac # #5 log4j.appender.stdout = Org.apache.log4j.ConsoleAppender6 log4j.appender.stdout.Target = System.out7 log4j.appender.stdout.layout = Org.apache.log4j.PatternLayout8 Log4j.appender.stdout.layout.ConversionPattern = [%-5p]%d{yyyy-mm-dd hh:mm:ss,sss} method:%l%n%m%n9 Ten # # # \u8f93\u51fadebug \u7ea7\u522b\u4ee5\u4e0a\u7684\u65e5\u5fd7\u5230=e://logs/error.log # # # One LOG4J.APPENDER.D = Org.apache.log4j.DailyRollingFileAppender A log4j.appender.d.file = E://logs/log.log - Log4j.appender.d.append = True - log4j.appender.d.threshold = DEBUG the log4j.appender.d.layout = Org.apache.log4j.PatternLayout - Log4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m%n - - # # # \u8f93\u51faerror \u7ea7\u522b\u4ee5\u4e0a\u7684\u65e5\u5fd7\u5230=e://logs/error.log # # # + LOG4J.APPENDER.E = Org.apache.log4j.DailyRollingFileAppender - log4j.appender.e.file =e://logs/error.log + Log4j.appender.e.append = True A log4j.appender.e.threshold = ERROR at log4j.appender.e.layout = Org.apache.log4j.PatternLayout -Log4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m%n
E://logs/log.log This is the log day path saved, use the Logs folder before creating
5 How to use
1 Packagecom.net.www;2 ImportOrg.apache.log4j.Logger;3 4 Public classTestday {5 Private StaticLogger Logger = Logger.getlogger (testday.class); 6 7 /** 8 * @paramargs9 */ Ten Public Static voidMain (string[] args) { One //System.out.println ("This is println message."); A - //record the debug level information -Logger.debug ("This is debug message.")); the //record information at info level -Logger.info ("This is info message.")); - //record the error level information -Logger.error ("This is error message.")); + } -}
6 operation results are as follows
SELENIUM-JAVA-LOG4J Environment Construction and