logger 报错

logger 报错:(log4j 起不来,log message打不出来)

No appenders could be found for logger (com.vip.qa.android.base.DriverFactory).
log4j:WARN Please initialize the log4j system properly.
在这里插入图片描述
原因: log4j.properties 文件没不存在,或存在,但放错路径

解:把log4j.properties放入mvn 默认的resources跑路径下面:./src/main/resources/

ok了:
logger 报错_第1张图片


依赖:

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.2</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

log4j.properties 文件:

### set base log level ###
log4j.rootLogger = debug

### set tesecase log level ###
log4j.logger.com.vip.qa.android=debug, stdout

### set remote server log level ###
log4j.logger.org.apache.http=off

### set proxy log level ###
log4j.logger.org.eclipse.jetty=info, stdout
log4j.logger.com.vip.test.proxy=info, file
 
### output log to console ###
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 = %-d{yyyy-MM-dd HH:mm:ss} [%t-%c]-[%p]  %m%n

### Define the file appender ###
log4j.appender.file=org.apache.log4j.FileAppender 
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t-%c]-[%p]  %m%n
log4j.appender.file.File=logs/${date}_${testCaseName}.log
log4j.appender.file.ImmediateFlush=true  
log4j.appender.file.Threshold=info 
log4j.appender.file.Append=true  
log4j.appender.file.encoding=UTF-8

要定义呀:

import org.apache.log4j.Logger;

public class TestVOS {

    private static Logger logger = Logger.getLogger(DriverFactory.class);
    
     @Before
    public void setUp() {
	……
	}
	
	 @Test
    public void sampleTest()
	……
	logger.info("用例执行成功");
	}

	 @After
    public void tearDown() {
        driver.quit();
    }
    
}

你可能感兴趣的:(java,java)