This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

No appenders could be found for logger despite log4j.properties file in the same jar

 
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to configure log4j for my core java application but getting error "log4j:WARN No appenders could be found for logger" and "Please initialize the log4j system properly".

Location of log4j.config: Inside the jar.

The jar of my application: myApp.jar has the log4j.properties file.

If i do jar -tf myApp.jar it shows the .class files and log4j.jar too.



If the log4j.properties file is in the jar and and i run Main.java class the log4j.properties file should be in the class path but it gives error message as above.




log4j.properties file:


#define the root logger with appender file
log = /home/user/
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.file.File=/home/user/loging.log

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n




Main.java class is in the jar and so is the log4j.properties.

I expected that when I run Main.java class it should automatically find log4j.properties since it is also inside the same jar.



Inside the Main.java, I have the below code:




(both the properties file as well as Main.java are in com folder)


despite that the error message which I recieve is:


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

Please advice.

Thanks

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because the log4j.properties is in the jar doesn't mean it's at the right location (the location that you are using within your code to load it). Furthermore the code you posted is eating any exception that might be thrown in the block which loads the file so you will have no idea if it was really loaded successfully. Have you tried debugging or at least printing out any exception stacktraces to see if there are any error while loading it?

Also, what exactly is the output of


 
Monica Shiralkar
Ranch Foreman
Posts: 1264
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks

when I do

jar -tf myApp.jar

I can see com.Main.class
log4j.properties
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I can see com.Main.class
log4j.properties



Please do post the exact output (copy/paste it here). If that's how it really looks like then your code is looking up that properties file in the wrong location. Have you improved your code to debug/log that exception in that block?
 
Bras cause cancer. And tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!