I have the log4j.properties file below which is being used when I deploy my application on Sun Java Web Server 7. The log file (../logs/myapp.log) is never created or appended to, can anyone suggest why?
Assuming that your statement that the properties file is being used is a true statement, then the answer to your question is quite likely: Your log file is being created and used. You are making an incorrect assumption about what directory that path is relative to.
Joined: Sep 12, 2003
Thanks, you bring up a good point -- it may be that the properties file is never being read. It lives in WEB-INF/classes/log4j.properties in my WAR file. I have enabled all debugging in my web server and there are no log messages indicating that there is a problem with log4j when I start my application. I have run a find command looking for the log file I specify in the log4j.properties and it is never found after the application is started, which leads me to believe that the log4j.properties is never read/used. I don't know of a way to verify that the properties file is being read/used. Is there a way to do so?
Joined: Sep 12, 2003
I'm not sure of what the problem was but now everything is working as expected. One thing I did which may have helped was that I modified the logging properties of my web server using the following wadm command:
I am just mentioning something that I consider as best practice , might be helpful but might not be what exactly you are looking for.
For any application that I create , I have a config directory which stores all the configuration files for my application and I pass it to the application as parameter like ; I can pass it to my initialization servlet as servlet config parameter.
In the init method of my initialization servlet (or any other appropriate place) I read the config dir path and append log4j.properties to that.It makes the full path of the log4j.properties and use it in PropertyConfigurator.
Again for specifying log file , I prefer specifying the full path of the file from the root of the filesystem.