5

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!

dbreaux
  • 4,982
  • 1
  • 25
  • 64
John
  • 477
  • 3
  • 8
  • 15
  • 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 Oct 03 '11 at 13:39
  • 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 Oct 03 '11 at 15:01
  • 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 Oct 03 '11 at 16:35

3 Answers3

4

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.

dbreaux
  • 4,982
  • 1
  • 25
  • 64
  • Thanks dbreaux, brilliant! It is exactly that issue! Really tough for a newbie to know all that, now turn to learn how to make a deployment plan, sigh! – John Oct 04 '11 at 09:19
1

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

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51
Manglu
  • 10,744
  • 12
  • 44
  • 57
  • Thanks Manglu, where to specify that switch? Sorry for my newbie question! – John Oct 04 '11 at 09:15
  • In the jvm arguments. -D will put the reference of the file available to log4j. See setting jvm args in google for the server you are using – Pat B Oct 05 '11 at 02:26
  • I use the anove approach in my application. Can i supply the file location in the custom properties instead of JVM arguments. Am using websphere 6.1 – siddhesh jog Mar 07 '12 at 12:37
0

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.

Pat B
  • 1,915
  • 23
  • 40
  • Thanks for your reply. I'm totally new to websphere, what is the correct way to set env, i read through the whole admin console but find none there? The best guess I try is to set that env var in C:\Program Files\IBM\WebSphere\AppServerCommunityEdition\bin and change log4j as suggested, it doesn't work either. – John Oct 02 '11 at 19:35
  • The setting of variables are done under server - process definition - custom properties – Pat B Oct 02 '11 at 19:49
  • I don't get "Process definition" under server, only Information, Java System Info, Server Logs, Shutdown, Web Server, Thread Pools, etc. I'm using Community Edition in windows and the console is in http://localhost:8080/ – John Oct 02 '11 at 21:52
  • @John: so it's not really WebSphere but Apache Geronimo. – home Oct 03 '11 at 08:36
  • Thanks home, I don't really know, I dl the IBM websphere communityEdition and maybe it use the Apache Geronimo. Anyway, i want to create log file out only from log4j but failed :~( – John Oct 03 '11 at 11:50
  • WebSphere CE is based on Geronimo. – dbreaux Oct 03 '11 at 13:35