-1

For some reason, I am getting the following error for logs. After doing some research and some comments from the previous posts, I have created a log4j file, but it still does not work. Any help is greatly appreciated.

log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.BasicClientConnectionManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
9009
  • 77
  • 1
  • 12
  • Can you post your log4j file? How are you configuring it? – cнŝdk Jun 05 '17 at 23:55
  • The log4j file should be in base directory or in resource folder – Murthi Jun 06 '17 at 02:50
  • I have kept it in the src/ folder of where I created my code files. Let say src/test/java is the path of my files. I have kept them in src folder. Should it be okay ? – 9009 Jun 06 '17 at 16:53
  • I have added it to src folder and it worked like charm. I just need to create a brand new project Java (without Maven) and placed the log4j.properties file. It worked good. I have also changed the log level from DEBUG to INFO. I got the output exactly how I need. Thank you very much chsdk and Murthi. – 9009 Jun 07 '17 at 03:25

1 Answers1

1

this is the manual please read through it URL for official manual

the very first thing you can do is in your main method call this

BasicConfigurator.configure();

or you can also add this in your log4j.properties

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

just make sure log4j.properties file is in your eclipse project classpath

Adeel Ahmed
  • 413
  • 4
  • 16
  • the error says we can not find log4j.xml or log4j.properties file. its a file used by log4j library to configure logging properties this is just a warning – Adeel Ahmed Jun 06 '17 at 00:00
  • I have added it to src folder and it worked like charm. I just need to create a brand new project Java (without Maven) and placed the log4j.properties file. It worked good. I have also changed the log level from DEBUG to INFO. I got the output exactly how I need. Thank you very much Adeel. – 9009 Jun 07 '17 at 03:24