Selenium-java-Log4j环境搭建和
1 导入Log4j ,我这版本是1.2.17 自己选择版本 **别告诉我不会导入
2 Path 奶瓶
3 创建一个与src同目录文件 命名为 log4.properties
4 文件的内容是, 直接复制,
### 设置根 定义###
log4j.rootLogger = info,stdout,I,E
##ERROR、WARN、 INFO、DEBUG###
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出info 级别以上的日志到=E://logs/error.log ###
log4j.appender.I = org.apache.log4j.DailyRollingFileAppender
log4j.appender.I.File = E://logs/log.log
log4j.appender.I.Append = true
log4j.appender.I.Threshold = info
log4j.appender.I.layout = org.apache.log4j.PatternLayout
log4j.appender.I.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志到=当前工程的logs文件夹中 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
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
log4j.rootLogger = info,stdout,I,E
##ERROR、WARN、 INFO、DEBUG###
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出info 级别以上的日志到=E://logs/error.log ###
log4j.appender.I = org.apache.log4j.DailyRollingFileAppender
log4j.appender.I.File = E://logs/log.log
log4j.appender.I.Append = true
log4j.appender.I.Threshold = info
log4j.appender.I.layout = org.apache.log4j.PatternLayout
log4j.appender.I.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志到=当前工程的logs文件夹中 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
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 这是保存的log日子路径,使用之前创建logs文件夹
5 使用方法
1 package com.net.www; 2 import org.apache.log4j.Logger; 3 4 public class testday { 5 private static Logger logger = Logger.getLogger(testday.class); 6 7 /** 8 * @param args 9 */ 10 public static void main(String[] args) { 11 // System.out.println("This is println message."); 12 13 // 记录debug级别的信息 14 logger.debug("This is debug message."); 15 // 记录info级别的信息 16 logger.info("This is info message."); 17 // 记录error级别的信息 18 logger.error("This is error message."); 19 } 20 }
6 运行结果如下