Log4j Could Not Read Configuration File SELENIUM JAVA -


how log4j read properties file.

i'm writing java testing selenium want use log4j. encounter error of log4j not read configuration file [error] ignoring configuration file . kindly advise , . in main method if have this:

 static logger log = logger.getlogger(testing.class); 

log4j.properties:

log4j.rootcategory=debug, r    # file    log4j.appender.r=org.apache.log4j.rollingfileappender    log4j.appender.r.file=d:/log4j.log     # control maximum log file size    log4j.appender.r.maxfilesize=100kb     # archive log files (one backup file here)    log4j.appender.r.maxbackupindex=1   log4j.appender.r.layout=org.apache.log4j.patternlayout     log4j.appender.r.layout.conversionpattern=[%d{iso8601}]%5p%6.6r[%t]%x - %c.%m(%f:%l) - %m%n 

my testcase :

@test  //tested login        public void testlogin_success() throws exception {           try{                //propertyconfigurator.configure("log4j.properties");               driver = new firefoxdriver();               loginbuilder.execute(driver);                 log.info("test test");               driver.quit();           }catch (exception e){                //log.error(e.getmessage());               throw (e);           }        } 

you can put log4j.properties file under resources folder corresponding java folder of class file.

also configure using configurator can use following code :

import org.apache.log4j.propertyconfigurator; ....your base class ....inside main/setup method propertyconfigurator.configure(testing.class.getclassloader().getresource("log4j.properties")); 

to make sure if logger working or not, can try , log same details console window , see differences. add these changes , observe :

log4j.rootcategory=debug, console, r  log4j.appender.console =org.apache.log4j.consoleappender log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p -> %m %n  

or in case conversionpattern=[%d{iso8601}]%5p%6.6r[%t]%x - %c.%m(%f:%l) - %m%n


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo