hi!
I am still not clear as to where I need to write this class or method.
Will it not suffice to give the entries in the web.xml file itself.
This is the first time I am dealing with these, so please help.

What I have done till now is to get the static logger instance in the class and then put the logger.debug("xx"); prints.
I need to know this :
a) In the struts framework, will it not suffice to just put entries in the web.xml
If not, then where in the framework should I write my class that uses the log4j apis?


Richie

At 12:50 PM 1/28/2004 -0500, you wrote:
Yup, that should work just fine. If you want to be able to modify the config
info while the app is running (e.g. turn on debugging in production without
reloading the app), here's another approach.

Create a directory and place it on the app server's classpath. For WLS
(depending on how you do your install and create your domains), it might be
something like C:\bea8\user_projects\domains\dotech\applib.

For each app, place a unique Log4j config file in the directory. For example,
app1-log4j.xml and app2-log4j.xml.

In your app's web.xml file, include <context-param> or <env-entry> elements for
the name of the config file and the watch delay value:


<env-entry>
  <description>Log4j resource file name</description>
  <env-entry-name>log4j/resource</env-entry-name>
  <env-entry-value>app1-log4j.xml</env-entry-value>
  <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

<env-entry>
  <description>Log4j resource file watch delay</description>
  <env-entry-name>log4j/watchDelay</env-entry-name>
  <env-entry-value>30000</env-entry-value>
  <env-entry-type>java.lang.Long</env-entry-type>
</env-entry>

Finally, create a context listener (or "startup" servlet) to perform the
configuration:

ClassLoader cl = Thread.currentThread().getContextClassLoader();
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");

String log4jResourceName = (String)envCtx.lookup("log4j/resource");
URL log4jResourceURL = cl.getResource(log4jResourceName);
String contentType = log4jResourceURL.openConnection().getContentType();
String fileName = log4jResourceURL.getFile();

Long log4jWatchDelay = (Long)envCtx.lookup("log4j/watchDelay");
long watchDelay = log4jWatchDelay.longValue();

if ("application/xml".equals(contentType)) {
  DOMConfigurator.configureAndWatch(fileName, watchDelay);
} else {
  PropertyConfigurator.configureAndWatch(fileName, watchDelay);
}

It's not so bad with some additonal help from Ant. I've also used this approach
to make it a bit less painful for multiple developers to share a single WLS
instance during development.


Quoting "Chappell, Simon P" <[EMAIL PROTECTED]>:

> Jacob,
>
> We use log4j 1.2.8 and we include the jar file right in out WEB-INF/lib
> directory of our application. The log4j.properties file then lives inside the
> WEB-INF/classes directory. This works well for us on IBM's WAS 4.x.
>
> I've never seen anyone recommend having log4j at the container level, so go
> with it at the application level and forget about conventional wisdom! :-)
>
> Hope this helps.
>
> Simon
>
> -----------------------------------------------------------------
> Simon P. Chappell [EMAIL PROTECTED]
> Java Programming Specialist www.landsend.com
> Lands' End, Inc. (608) 935-4526
>
> "Wisdom is not the prerogative of the academics." - Peter Chappell
>
> >-----Original Message-----
> >From: Hookom, Jacob [mailto:[EMAIL PROTECTED]
> >Sent: Wednesday, January 28, 2004 11:08 AM
> >To: Struts Users Mailing List
> >Subject: [OT] RE: log4j integration
> >
> >
> >I'm wondering if anyone has gotten log4j to be deployed within separate
> >apps? We are having issues with log4j jars and their
> >properties files being
> >deployed on each application under Weblogic. Most of what I've read
> >recommends putting log4j at the container level along with a single
> >properties file, but that isn't as flexible as what we want it to be.
> >
> >-Thanks
> >
> >-----Original Message-----
> >From: [EMAIL PROTECTED]
> >[mailto:[EMAIL PROTECTED]
> >
> >Sent: Wednesday, January 28, 2004 10:20 AM
> >To: [EMAIL PROTECTED]
> >Subject: RE: log4j integration
> >
> >Hi,
> >Also there is something called
> >ReloadingPropertyConfigurator..May be this in
> >combination with HierarchyEventListener will do the trick for you.
> >
> >I mean the log4j API is so feature rich, you should not be
> >required to write
> >something for such a common task.
> >
> >regards,
> >Shirish.
> >
> >-----Original Message-----
> >From: Geeta Ramani [mailto:[EMAIL PROTECTED]
> >Sent: Wednesday, January 28, 2004 4:02 PM
> >To: Struts Users Mailing List
> >Subject: Re: log4j integration
> >
> >
> >*Yes*!! The LogManager is the ticket - I didn't know about
> >this class, so
> >tried it
> >out. Works like a charm.. :) Thanks, Shirish (I think? I
> >inadvertently
> >erased the
> >response to this question so am not sure of its author..)
> >
> >Geeta


--
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

"To achieve all that is possible, one must attempt the impossible"




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to