• 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

Issues logging with log4j

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to get my application to log using the log4j jar. It works fine in Dev Mode, but when I deploy it to tomcat the log files denoted by the configuration don't even seem to appear.

The following log4j.properties file is in my war directory for my app:


Just to get it working I have a simple class with static log methods only accessing the rootLogger:


On server side calls I simply have statements such as:


Are there settings within the Tomcat environment to allow application specific use of log4j, or am I simply going about this wrong? I have read in a few places about people saying to put my .properties file into WEB-INF/classes directory, but when my war file is unpacked by Tomcat I don't see that directory.
 
Chaz Cowan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a few resources detailing how the Catalina.policy file by default only allows web applications "read" access to files. Is this true?

I've been trying to alter the policy file to allow my application read/write/execute, but am so far unable to do so.

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you don't need to muck around with your Tomcat or JVM settings - and especially not the security settings.

It is better, however, if you give an absolute pathname and not a relative name for your logfile, and yes, the log4j.properties file must be located in the WEB-INF/classes directory of your WAR. Whether Tomcat exploded it out or not, it does have to be in the orignal WAR that you deploy.

Incidentally, just in case you didn't know - and it's not well documented - when an exploded WAR is detected in the Tomcat webapps directory and an unexploded WAR is present in the same directory, the exploded WAR is the one that gets used. Even if the unexploded WAR is newer than the exploded WAR! The safest way to deploy is either to delete both exploded and unexploded copies before updating or to turn off the option to explode.
 
Chaz Cowan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:No, you don't need to muck around with your Tomcat or JVM settings - and especially not the security settings.

It is better, however, if you give an absolute pathname and not a relative name for your logfile, and yes, the log4j.properties file must be located in the WEB-INF/classes directory of your WAR. Whether Tomcat exploded it out or not, it does have to be in the orignal WAR that you deploy.

Incidentally, just in case you didn't know - and it's not well documented - when an exploded WAR is detected in the Tomcat webapps directory and an unexploded WAR is present in the same directory, the exploded WAR is the one that gets used. Even if the unexploded WAR is newer than the exploded WAR! The safest way to deploy is either to delete both exploded and unexploded copies before updating or to turn off the option to explode.



Ok I removed the entry I tried to make in the catalina.policy file just in case that would mess stuff up.

I also altered my ANT build file so that it includes the log4j.properties, and the file now ends up in the WEB-INF/classes directory when Tomcat unpacks the WAR file.

I altered my log4j.properties file to use absolute paths for the log files to see if that would help(I tried it with "\\" and "/" and "\" delimeters):


It still doesn't seem to want to log anything, or even create the log files themselves. I even stopped the server, deleted everything, then copied my WAR file into webapps, then restarted it each time I changed anything. Any other ideas?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I make no guarantees, but file/directory names with spaces in them are trouble. Instead of "Program files" &co, try creating a "C:\logs" directory and specify things like:


Since I use the XML form for log4j specs, I can't really tell if there's any general fault in the log4 properties file.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic