• 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

Log4J and WebSphere - will it fly?

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all- thanks in advance for reading this long post:
Anyone had success implementing log4J in WAS?
We’re having the following problem trying to implement Log4J into WAS 4.
In WSAD (4.0.2) we put the Log4J jar in the classpath and the log4j properties file in the application directory (default classpath). We have a wrapper class (LogUtil) that calls log4J that is in the EJB tier. Both EJBs and Web components call LogUtil to get an instance of the logger. Works great in dev.
The problem happens when we try to move the app to WAS on AIX.
1) Can’t find the properties file unless it is in a jar. This doesn’t help as we want to be able to modify the properties file via a JSP, so that we can have dynamic logging. I’ve tried others ways (as seen on this forum) to get a property file from a file system but not had much luck. Not sure how I can I set the working directory in WSAD to match that of WAS—-application developer? One concern I have is that in a distributed environment, a prop file used by different tiers is probably not a good thing.
2) Multiple class loaders: not an issue in WSAD but a conflict in WAS.
Thoughts:
 put the prop file in the DB, eliminate classpath and distributed issues? And cause a potential performance issue?
 two loggers?
 Two property files?
 Dump log4j?
thanks!
Max Tomlinson
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Max

Originally posted by Max Tomlinson:

Anyone had success implementing log4J in WAS?


Yes, even on AIX



1) Can’t find the properties file unless it is in a jar. This doesn’t help as we want to be able to modify the properties file via a JSP, so that we can have dynamic logging. I’ve tried others ways (as seen on this forum) to get a property file from a file system ...


What Java code are you using to load the property file ? It should work.
The way we've done it on a specific project is :
- the log4j properties are in a xml file
- the xml file can be anywhere. A system property allows to find its path. So it is configurable within both WAS and WSAD.
- the log4j jars are within the EAR file.
Each module using them has a dependency through the MANIFEST (edit module dependencies with WSAD)



2) Multiple class loaders: not an issue in WSAD but a conflict in WAS.


Ah !! multiple classloaders... :roll:
What kind of visibility are you using in WAS ?



Thoughts:
 put the prop file in the DB, eliminate classpath and distributed issues? And cause a potential performance issue?


Bad idea IMHO. Imagine the hits each time you have to log !!
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Bill-
thanks for the reply:
One approach we've used is a ResourceBundle to load the properties file but it's only succesful if the prop file is in a jar...otherwise it can't find it...
when you say a 'A system property allows to find its path.' what exactly do you mean? A classpath setting?
also, I did not understand: 'What kind of visibility are you using in WAS ? ' .. maybe I'm missing soemthing here in WSAD...
If you're using log4j in your project, are you using both EJBs and the web tier to log? Where do you put the log4j.jar? We've put ours in the enterprise application and reference that jar in the ejb projects and the war project...
also, where exactly do you put your xml file?
many thnaks,
max Tomlinson
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Max Tomlinson:

when you say a 'A system property allows to find its path.' what exactly do you mean? A classpath setting?


Nope. A JVM system property.
In the JVM settings tab of WAS, you can define a JVM variable, say, MyLog4JProps, which value is the path of the xml file.
(/usr/WebSphere/AppServer/...)
The you can obtain the value of the property using :
System.getProperty("MyLog4JProps");


also, I did not understand: 'What kind of visibility are you using in WAS ? ' .. maybe I'm missing soemthing here in WSAD...


For your appServer within WAS (general tab), you can have
- module visibility
- server visibility
- application visibility
- compatibility visibility
Wich one are you using ?
(there also a J2EEApplication mode... from ptf3)


If you're using log4j in your project, are you using both EJBs and the web tier to log? Where do you put the log4j.jar? We've put ours in the enterprise application and reference that jar in the ejb projects and the war project...


Yep, both with EJB and War.
The log4j jar files (2) are directly under the ear file, and we reference them using "edit module dependencies" in WSAD
How do you reference the jars ?
Can you doublecheck the jars are specified within your MANIFEST.MF files ?


also, where exactly do you put your xml file?


Wherever you want.
Yhe path is defined by the JVM proprty decribed above (MyLog4JProps)
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill-
many thanks for the reply...
In WAS (not WSAD), the visibility is 'module'...
what should it be for log4j to be shared with multiple tiers?

(think I'm getting closer...)
regards,
Max
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YEAH!
I set the WAS visibilty to application and it works with one jar and one properties file!
I feel as if I've discovered a lost chapter of the bible...
thanks a lot BILL,
Max Tomlinson
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great !
Now you can read the Infocenter about visibility to understand better what happened.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic