我正在使用由如下所示的几个日志方法组成的侦听器类来记录 TestNG 测试。我只想在我的控制台中打印侦听器类日志,并且完整日志应该转到 FullLog 文件。完整日志正在移动到完整日志文件,但在控制台中我得到了完整日志和侦听器类日志。我如何配置相同的 log4j 属性文件。
监听类:
public class SimpleListener implements ITestListener {
private static Logger m_log = Logger.getLogger(SimpleListener.class);
public void onFinish(ITestContext itestcontext) {
m_log.info("onFinish() is called"); }
public void onStart(ITestContext itestcontext) {
m_log.info("onStart() is called");
}
}
我的 log4j 属性文件:
log4j.rootLogger=INFO, FullLogAppender, ConsoleAppender
log4j.logger.TestLog=INFO, BreakPointAppender
#Console Log Appender
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.ConsoleAppender.Target=System.out
#Full Log Appender
log4j.appender.FullLogAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FullLogAppender.File=mfgLogs/FullLogs/FullLog.log
log4j.appender.FullLogAppender=org.apache.log4j.RollingFileAppender
log4j.appender.FullLogAppender.layout.ConversionPattern=%d %-5p %c %x- %m%n
log4j.appender.FullLogAppender.Append=false Dec 12 12:41:11 IST 2012
控制台中的预期结果:
11:29:33,159 INFO SimpleListener:15 - onStart() is called
11:29:50,372 INFO SimpleListener:31 - runTest.....
11:30:23,637 INFO SimpleListener:23 - Failed
11:30:24,402 INFO SimpleListener:12 - onFinish() is called