• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Ranch Hand
Posts: 2966
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Hand
Posts: 2966
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic