Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4j configuration in webapplication

 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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... )
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
That was first obvious thing i tired, but is not working. Any ideas
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next obvious thing to try:

Final obvious thing to try is the thing which you already had working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic