• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j:WARN Please initialize the log4j system properly

 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am trying to implement logger concept in my java application.

For testing purpose I am creating a Test.java file .I have added the log4j-1.2.9.jar.
I am not getting any compilation error. While executing the Test.java I am getting
Exception
log4j:WARN No appenders could be found for logger (Log4jTest.Test).
log4j:WARN Please initialize the log4j system properly.


Please suggest me how to fix this error.

Code
Test.java


log4j.properties


Thanks for your time.

Regards,
Sumanta Panda
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is log4j.properties in the classpath when the program executes?
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Nathan,
Its log4j.properties not in the classpath when the program executes.

Requesting you to please provide the solution how to fix it.

Thanks for your time.

Regards,
Sumanta Panda

 
yuvaraaj mohan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Which application server are you using?

Cheers,
Yuvaraj.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Tomcat 6, drop it in Tomcat's lib folder and it will apply for all web apps.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sumanta ,

Before calling methods of log4j , the log4j configuration should be done. Either configured directly in code or through log4j.properties or xml file.



If you use log4j.properties , it should be in the classpath for the configuration to be used , make sure its copied to classes folder in-case of web application.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am using the logger concept in a Standalone java program with RAD tool.

My Folder Structure is::
D:\workspace_Log4j\Log4jTest
D:\workspace_Log4j\Log4jTest\src
D:\workspace_Log4j\Log4jTest\bin
D:\workspace_Log4j\Log4jTest\lib\ log4j-1.2.9.jar
D:\workspace_Log4j\Log4jTest\ log4j.properties

Please suggest me if my folder structure is wrong.

My doubt is how Test.java is knowing we are using log4j.properties file?Do we need to initialize the log4j.properties in my Test.java file?

How can i use log4j.properties in the classpath configuration ?

Thanks for your time.
Please suggest how i fix this error.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
This issue has been resolved after copied the log4j.properties in the src location D:\workspace_Log4j\Log4jTest\src\ log4j.properties .

Thanks to all.


Best Regards,
Sumanta Panda
Tcs
 
Chandra Mouli Kakara
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please find the below steps to solve the issue

Issue :
log4j:WARN No appenders could be found for logger (com.app.MyLogger).
log4j:WARN Please initialize the log4j system properly.


Solution :
1)download log4j-1.2rc1-2002-04-16.jar file
2)Add the log4j-1.2rc1-2002-04-16.jar file to build path
3)create object private static org.apache.log4j.Logger log= Logger.getLogger(MyLogger.class);
4)once you run the Mylogger.java file system will automatically creates the log4j.properties file
5)find out the log4j.propertiesfile and replace the contents as per the requirements(mostly system will creates in bin directory)
6)if not find log4j.properties file create one new file in bin directory (/workspace/projectdirectory/bin/)
6)log4j.properties
log4j.rootLogger=debug, 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=%t %-5p %c{2} - %m%n



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason you are suggesting downloading an old release candidate version of log4j, rather than an official build?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic