5
votes

I recently take over a web application project using websphere and log4j running under AIX. To create a development environment, I setup all the components in windows, using eclipse to compile a WAR file and deploy it.

All is working fine except that log file is not created. I changed the log file in log4j.properties from something like in below and and give everyone full access permission to the directory:

log4j.appender.F1.File=/abc/def/logs/admin.log

to

log4j.appender.F1.File=c:/logs/admin.log

What else can I check?

I create a simple standalone testapp which use the same log4j.properties and it can create the log file, but when the servlet deployed to websphere, it doesn't work. Please help! Thanks!

3
Did you place log4j.properties in WEB-INF/classes in your WAR file? Did you look for admin.log in another location on the filesystem? Does the stdout or stderr log (I don't know where these are in CE) show any log4j-related errors? What you're doing should work, so I'd guess that the log4j.properties file isn't being used.dbreaux
Yes, log4j.properties is inside WEB-INF/classes in the WAR file. I guess the log4j.properties is ok as i changed output patterns and it does work for the console output.John
The log4j.properties is inside but somehow it is not read by log4j. I forced that code and is working, but how to make tomcat use the one in WEB-INF/classess without hardcoding? The code: PropertyConfigurator.configure("C:\\test\\log4j.properties");John

3 Answers

4
votes

Ok, I think this article should help you. It seems that WebSphere CE uses log4j by default and controls it with a global properties file. There is a section on how to use application-specific properties files.

1
votes

Here is what I try and do to troubleshoot similar issues.

  1. Turn on log4j debugging to see where it actually picks up the file from. You need evidence of which file is picked up (so turning the debug on is a worthwhile activity) This provides you information with what log4j is trying to do to locate the configuration file.

    -Dlog4j.debug=true

  2. I would not hardcode the log4j location in the code. Instead I would use the log4j.configuration System property and state that in the JVM arguments. This way even I don't need to touch my code.

    -Dlog4j.configuration=file:///home/manglu/log4j.properties

I would use this approach irrespective of the runtime server that I use (be it Tomcat or WAS CE or WAS)

Hope this helps

0
votes

I suggest you use environment variables set on your server like this :

You must access the admin console of your server. Under custom properties

Server_path=/abc/def/logs

In your log4j, use this : {$server_path}/log.txt

Make sure the user running the app has access to that directory.