8

I tried to configure log4j with `log4j.properties' file.

All work but but I caught some strange warning:

log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I couldn't figure out what is wrong with this. All should work.

Content of log4j.properties:

# Root logger option
log4j.rootLogger=warn, stdout, file 

# Direct log messages to stdout
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{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.file=logs/oms_test.log
log4j.appender.file.MaxFileSize=2MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 

log4j.appender.debugfile=org.apache.log4j.RollingFileAppender
log4j.appender.debugfile.file=logs/oms_test-debug.log
log4j.appender.debugfile.layout=org.apache.log4j.PatternLayout
log4j.appender.debugfile.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n 
log4j.logger.com.softserve.edu=DEBUG, debugfile
log4j.logger.com.my.app.somepackage.subpackage.ClassName=INFO

Here is struckture of project:

project struckture

EDIT:

I load log4j.properties from code:

PropertyConfigurator.configure("src/resourses/log4j.properties");
Logger.getRootLogger();

Edit2:

I tried change location log4j.properties at different location as src/main/resourses or src/test/resourses, src/resourses and changed loading from code.

And always it fails:

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:97)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:372)
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403)
    at com.softserve.edu.SearchingOrdersPageTest.setUp(SearchingOrdersPageTest.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
log4j:ERROR Ignoring configuration file [log4j.properties].
  • How to solve this trouble?
catch23
  • 17,519
  • 42
  • 144
  • 217

4 Answers4

4

Put log4j.properties to bin (classpath) may solve your problem.

Engine Bai
  • 626
  • 1
  • 7
  • 16
  • How to do this exactly? to put into JRE System Library? and I call it from code. – catch23 Nov 27 '13 at 16:17
  • 2
    Sorry, I don't notice that you use maven project structure. You can put `log4j.properties` to 'src/main/resources' folder. Create the folder manually if not exist. – Engine Bai Nov 27 '13 at 16:23
  • I tried `src/resourses` one but without success. It can't read from there. And tried `src/test/resourses`. I'll we see if problem is here... – catch23 Nov 27 '13 at 18:55
  • I did this it throws `log4j:ERROR Could not read configuration file [log4j.properties].` from `src/main/resources`. – catch23 Nov 28 '13 at 09:49
4

I had the same problem, and I've solved it when I put log4j.xml in WEB-INF/classes

Check this post and answer initialize log4j.

A.Vila
  • 1,456
  • 4
  • 21
  • 32
0

Where ever you put log4j.properties make sure you call that using propertyconfigurator as shown below

     PropertyConfigurator.configure("D:\\logs\\log4j.properties");    

     final Logger  LOGGER = Logger.getRootLogger();
     LOGGER.info("sddd");
     LOGGER.debug("ffff");**
Sanjay
  • 117
  • 4
  • 13
-1

just paste the below code.

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
System.setProperty("webdriver.chrome.driver","C:\\Users\\gwda\\Desktop\\chromedriver.exe"); 
WebDriver s1 = new ChromeDriver();

This may resolve your trouble.

catch23
  • 17,519
  • 42
  • 144
  • 217
NGOWDA
  • 9
  • 1
  • 4