RE: Re[2]: Servlets JSPs log to different files

2003-08-04 Thread Shapira, Yoav

Howdy,
I would point out a couple of things, since you posted this code as an
example, but they are subjective.

I have a servlet that is loaded at the time tomcat starts.

The container is free to destroy and reload this servlet as it deems
necessary.  Accordingly, use a ServletContextListener instead.

   DOMConfigurator domConfig;

Should be private?  And inside the method rather than a servlet instance
variable?

then in the class (bean) that has no idea about the context i have the
following:
   protected org.apache.log4j.Logger logWriter =
   org.apache.log4j.Logger.getLogger(nameoffiletoappearinlog);

Why is this protected?  You almost always want loggers to be private
(static, and final).

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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



Re[2]: Servlets JSPs log to different files

2003-08-01 Thread Kenneth Brooks
I currently do the following.
See the 3 or 4 sections of code below.

I have a servlet that is loaded at the time tomcat starts.
Pay no attention to the crap coding in this file, but you get the idea

 BEGIN EimplementLogger.java ///
package whateverpackage.log;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.log4j.xml.*;

import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.InitialContext;

public class EimplementLogger extends HttpServlet {
   DOMConfigurator domConfig;

  public void init() throws ServletException {
 // init code here
 domConfig = new DOMConfigurator();

 // point to log4j configuration file
 Context ctx = null;
 String log4jxmlfilepath = null;

 try {
ctx = new InitialContext();
 } catch (NamingException e) {
//   System.out.println(Couldn't build an initial context :  + e);
   return;
 }

 try {
log4jxmlfilepath = (String)(ctx.lookup(java:/comp/env/log4jxmlfilepath));
 } catch (NamingException e) {
   System.out.println(JNDI lookup failed :  + e);
 }

 domConfig.configure(log4jxmlfilepath + log4j.xml);
   }

}
/ END EimplementLogger.java 

In my web.xml i have the following to start this servlet up.
servlet
servlet-name
EimplementLogger
/servlet-name

servlet-class
whateverpackage.log.EimplementLogger
/servlet-class
load-on-startup5/load-on-startup
/servlet

then in the class (bean) that has no idea about the context i have the
following:
   protected org.apache.log4j.Logger logWriter =
   org.apache.log4j.Logger.getLogger(nameoffiletoappearinlog);

and i use it like so
logWriter.debug(here is a debug statement);

hope that helps

-ken






Friday, August 1, 2003, 8:51:28 PM -\][/

AB G'day,

AB Can anyone expand on this further and explain how to use a Log4j logger
AB reference in beans that do not have a notion of what the underlying servlet
AB context is?  The only way I can see how to get this to work is to pass the
AB logger reference as an argument in the bean's constructor.  

AB My query does seem to be out of context for this list so my apologies in
AB advance.

AB AB

AB -Original Message-
AB From: Shapira, Yoav [mailto:[EMAIL PROTECTED] 
AB Sent: Saturday, 2 August 2003 3:24 AM
AB To: Tomcat Users List
AB Subject: RE: Servlets  JSPs log to different files



AB Howdy,
AB Then use log4j.

AB Yoav Shapira
AB Millennium ChemInformatics


-Original Message-
From: Rick Roberts [mailto:[EMAIL PROTECTED]
Sent: Friday, August 01, 2003 1:18 PM
To: Tomcat Users List
Subject: Re: Servlets  JSPs log to different files



 How are you logging in your servlets?  Are you using 
 System.out/System.err?  If so, don't use them, and instead use the
 ServletContext#log(..) methods.

Actually, they are mostly beans with no ServletContext :(

--
***
* Rick Roberts*
* Advanced Information Technologies, Inc. *
***


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




AB This e-mail, including any attachments, is a confidential business
AB communication, and may contain information that is confidential, proprietary
AB and/or privileged.  This e-mail is intended only for the individual(s) to
AB whom it is addressed, and may not be saved, copied, printed, disclosed or
AB used by anyone else.  If you are not the(an) intended recipient, please
AB immediately delete this e-mail from your computer system and notify the
AB sender.  Thank you.


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




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




/][/-\][\


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



Re[2]: servlets

2003-01-28 Thread Jacob Kjome
Hello Felipe,

Note that the invoker servlet provided in Tomcat as the mapped path
/servlet/* will create a separate instance of your servlet to one that
you access via a normal servlet mapping such as /myservlet.

So, you *can* get two instances of a particular servlet at one time.
Disabling the invoker servlet (as is the default currently) resolves
this issue, however.

Jake

Tuesday, January 28, 2003, 4:43:36 PM, you wrote:

FS   Yes, that's cool :-)))
FS   Anyway, if you have multiple tomcats one would not see others
FS instances, so no prob at all.
FS   I don't think anyone would use SingleThreadModel... it's practically
FS useless

FS On Tue, 2003-01-28 at 20:32, Wendy Smoak wrote:
 Craig wrote
  The servlet spec guarantees that you will get a single instance of a
  non-SingleThreadModel servlet PER servlet DEFINITION for that webapp.
  See Section SRV.2.2 of the Servlet 2.3 spec for the formal details.
 
 Interesting... I was under the impression that the container was free to
 create as many instances of your Servlet as it wanted to, but that appears
 to be the case *only* for SingleThreadModel.  (Does anyone actually _use_
 that?)
 
 So as long as you're not in a distributed environment [multiple Tomcats?]
 and not implementing SingleThreadModel, it appears you *can* assume that
 there will be only one instance of your Servlet.
 
 -- 
 Wendy Smoak
 Applications Systems Analyst, Sr.
 Arizona State University PA Information Resources Management
 



-- 
Best regards,
 Jacobmailto:[EMAIL PROTECTED]


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