在log4j文件中调试

时间:2017-03-28 17:49:05

标签: selenium log4j

你好,我是硒的新手。我正在努力学习log4j。我的程序运行成功后,生成log4j报告“debug”和“info”,但我只想显示“info”。

我的节目:

package demo_pack;

import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.apache.log4j.*;

public class  log_prac
{
static WebDriver driver;
public static void main(String []args)
{
    BasicConfigurator.configure();
    Logger log = Logger.getLogger("log_prac");
    PropertyConfigurator.configure("log4j.properties");
    System.setProperty("webdriver.chrome.driver", "D:\\rakesh\\Selenium\\selenium browsers\\chromedriver.exe");
    driver=new ChromeDriver();
    log.info("browser opened");
    driver.get("https://www.youtube.com");
    log.info("navigated to youtube");
    //log.error("unable to navigate youtube");
    driver.close();
    log.info("browser closed");
}
}

我的log4j.property:

# Here we have defined root logger
log4j.rootLogger=ALL,CONSOLE,R,HTML,TTCC

# Here we define the appender
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.TTCC=org.apache.log4j.RollingFileAppender
log4j.appender.HTML=org.apache.log4j.FileAppender

# Here we define log file location
log4j.appender.R.File=./log/testlog.log
log4j.appender.TTCC.File=/log/testlog1.log
log4j.appender.HTML.File=./log/application.html

# Here we define the layout and pattern
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern= %5p [%t] (%F:%L)- %m%n
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d - %c -%p -%m%n
log4j.appender.TTCC.layout=org.apache.log4j.TTCCLayout
log4j.appender.TTCC.layout.DateFormat=ISO8601
log4j.appender.HTML.layout=org.apache.log4j.HTMLLayout
log4j.appender.HTML.layout.LocationInfo=true

1 个答案:

答案 0 :(得分:0)

您可以在log4j.properties文件的第一行放置“INFO”而不是“ALL”。所以基本上它看起来像:

log4j.rootLogger = INFO,CONSOLE,R,HTML,TTCC