• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4j configuration in webapplication

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to make changes to an application which uses a natively developed logging class. We have integrated log4j with custom class, so that it behined the scene log4j is used for logging

Right now the log4j.properties is read using


We have placed the log4j.properties in root of src direcotry, i.e the code structure is as follows
src
|
|--->com
| |
| |-->testcompany
| | |
| | |-->util
| | | |
| | | | -->someutil.java
| |
|->log4j.properties


What we want to do is instead of reading from root of src we want to read from config/LogConfig directory like show below


src
|
|--->com
| |
| |-->testcompany
| | |
| | |-->util
| | | |--someutil.java
| |
| |
| |-->Config
| | |
| | |-->LogConfig
| | | |
| | | |--log4j.properties

I tried to set the same thing via propertyconfigurator, as shown below but it is not working



can someone please throw some light

Thanks for all the help

 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Web applications don't have a "src" directory. Their classes are stored either in WEB-INF/classes or in a jar in WEB-INF/lib. So you should base your design planning on that rule. Once you have figured out where you want the config file to go (I put mine in WEB-INF/classes) then you can figure out how to get your deployment procedure (where you build your WAR or EAR for the application) to put it there.

(Also you might want to spell "congfig" better than that... )
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot speak for other containers (although I would think it would be similar), but for Tomcat, all that is required is that "log4j.properties" exist directly under WEB-INF/classes or WEB-INF/lib in my web application, along with the log4j jar file in WEB-INF/lib.

If log4j-xxx.jar is located on the web application's classpath (ie WEB-INF/lib), Tomcat should attempt to implement log4j. If I am missing my log4j.properties, it sends a message to standard out (catalina.out) that log4j was not properly initialized.



Also, I haven't had to call "PropertyConfigurator.configure("log4j.properties");", it's generally been enough simply to call
 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul & Pete,

Thanks for the response.

Paul,

I have currently in WEB-INF/classes/log4j.properties -- works

When i place the file in WEB-INF/classes/com/somecompany/config/log4j.properties -- does not work

Please let me know how can i read from com/somecompany/config directory

Thanks for all the help

 
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
As far as I know, the PropertyConfigurator uses the classloader to lookup the resource (i.e. the config file). So I guess this should work:

 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was first obvious thing i tired, but is not working. Any ideas
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Next obvious thing to try:

Final obvious thing to try is the thing which you already had working.
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic