我试图将系统生成的日志保存在Selenium.log文件中,并将手动日志保存在Application.log文件中。 log4j.properties如下所示
#Root Logger option
log4j.rootLogger = debug, file
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File = C:\\Users\\user\\eclipse-workspace\\DataDrivenFrameworkMaven\\src\\test\\resources\\logs\\Selenium.log
log4j.appender.file.maxFileSize = 5000KB
log4j.appender.file.maxBackupSize = 1
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{5}:%L - %m%n
#Do not append the old file. Create a new log file everytime
log4j.appender.file.Append = false
#Application Logs
log4j.logger.devpinoyLogger = DEBUG, dest1
log4j.appender.dest1 = org.apache.log4j.RollingFileAppender
log4j.appender.dest1.File= C:\\Users\\user\\eclipse-workspace\\DataDrivenFrameworkMaven\\src\\test\\resources\\logs\\Application.log
log4j.appender.dest1.maxFileSize = 5000KB
log4j.appender.dest1.maxBackupIndex = 3
log4j.appender.dest1.layout = org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern = %d{dd/MM/yyyy HH:mm:ss} %c %m%n
#Do not append the old file. Create a new file every time
log4j.appender.dest1.Append = false
但是,两个文件中都只保存了手动日志信息。系统生成的日志信息未保存在Selenium.log文件中。这两个文件的输出如下:
Application.log
14/11/2018 20:03:40 devpinoyLogger Config file is loaded.
14/11/2018 20:03:40 devpinoyLogger OR file is loaded.
14/11/2018 20:03:43 devpinoyLogger Chrome browser is launched.
14/11/2018 20:03:49 devpinoyLogger Navigted to http://www.way2automation.com/angularjs-protractor/banking/#/login
14/11/2018 20:03:49 devpinoyLogger Inside Login Test
14/11/2018 20:03:49 devpinoyLogger Login Test successfully executed
14/11/2018 20:03:50 devpinoyLogger Test execution completed
Selenium.log
20:03:40,725 DEBUG devpinoyLogger:40 - Config file is loaded.
20:03:40,728 DEBUG devpinoyLogger:53 - OR file is loaded.
20:03:43,330 DEBUG devpinoyLogger:61 - Chrome browser is launched.
20:03:49,129 DEBUG devpinoyLogger:74 - Navigted to http://www.way2automation.com/angularjs-protractor/banking/#/login
20:03:49,161 DEBUG devpinoyLogger:13 - Inside Login Test
20:03:49,305 DEBUG devpinoyLogger:16 - Login Test successfully executed
20:03:50,326 DEBUG devpinoyLogger:87 - Test execution completed