| Author |
Log file not being created or appended to with log4j
|
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
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? log4j.rootCategory=WARN,FILE log4j.logger.com.mycom.myapp=TRACE log4j.appender.FILE=org.apache.log4j.RollingFileAppender log4j.appender.FILE.File=../logs/myapp.log log4j.appender.FILE.MaxFileSize=1000KB log4j.appender.FILE.MaxBackupIndex=1 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.ConversionPattern=[%p %d{DATE} %t %C{1}] %m%n Thanks in advance for any help! --James
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
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.
|
 |
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
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? --James
|
 |
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
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: wadm set-log-prop --user=admin --host=localhost --port=8989 --config=ja-z1 log-virtual-server-name=true log-stdout=true log-stderr=true log-level=fine --James
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
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.
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
 |
|
|
subject: Log file not being created or appended to with log4j
|
|
|