RE: How to use Log4j with a startup logging servlet

2002-01-16 Thread Jenkins, David

Hi Eric, here's how use Logging to provide method call logging.

import org.apache.log4j.Category;

public class myclass {

  private static final Category log = Category.getInstance(myclass .class);

  public void mymethod() {
try {
  log.debug("enter mymethod");
}
finally {
  log.debug("exit mymethod");
}
  }
}

Dave

-Original Message-
From: Eric L. Ma [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 16 January 2002 3:58 p.m.
To: 'Struts Users Mailing List'
Subject: RE: How to use Log4j with a startup logging servlet


Thanks, gentlemen.  I start to get the idea but am still fuzzy on how to
issue logging requests in my custom Action classes.  Do I have to
declare a static Category variable in each and every Action class I
write?  Please share some code on how logging is actually done, now that
I know how to set up the startup servlet.

Eric

-Original Message-
From: Eric Ma [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 15, 2002 12:33 PM
To: [EMAIL PROTECTED]
Subject: How to use Log4j with a startup logging servlet

I want to use Log4J for logging exceptions thrown in a Struts-based web
app.  After searching through this list, I found 2 common solutions:

1. Extend the Struts ActionServlet and override the init() method to set
up a Log4J Category.  Then in any custom Action class I can just call
servlet.Category.debug() (let's assume Category is a protected or public
variable).

2. Write a separate startup servlet and again set up LOG4J in the init()
method.  But my question is, how do I invoke this servlet from my custom
Action class?  Do I need to do a RequestDispatcher.forward() to the
servlet when an exception is thrown?  Then how do I get back to the page
I am on to display the error message?

Eric Ma


--

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



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


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


This message contains official information which is intended
for the use of the addressee(s) only.  If you are not the
intended recipient, please notify the sender immediately.
You should not further disseminate or copy this message
in any way.
*

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




RE: How to use Log4j with a startup logging servlet

2002-01-16 Thread Eric L. Ma

Thanks, gentlemen.  I start to get the idea but am still fuzzy on how to
issue logging requests in my custom Action classes.  Do I have to
declare a static Category variable in each and every Action class I
write?  Please share some code on how logging is actually done, now that
I know how to set up the startup servlet.

Eric

-Original Message-
From: Eric Ma [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 15, 2002 12:33 PM
To: [EMAIL PROTECTED]
Subject: How to use Log4j with a startup logging servlet

I want to use Log4J for logging exceptions thrown in a Struts-based web
app.  After searching through this list, I found 2 common solutions:

1. Extend the Struts ActionServlet and override the init() method to set
up a Log4J Category.  Then in any custom Action class I can just call
servlet.Category.debug() (let's assume Category is a protected or public
variable).

2. Write a separate startup servlet and again set up LOG4J in the init()
method.  But my question is, how do I invoke this servlet from my custom
Action class?  Do I need to do a RequestDispatcher.forward() to the
servlet when an exception is thrown?  Then how do I get back to the page
I am on to display the error message?

Eric Ma


--

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



--
To unsubscribe, e-mail:

For additional commands, e-mail:



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: How to use Log4j with a startup logging servlet

2002-01-16 Thread Alex Colic

Hi,

I have used option two.

The code for my servlet is below. It works for me. If you have any
suggestions, enhancements please send me a note.

Alex



package com.sirius.struts.action;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;


public class genericLog4JServlet extends HttpServlet
{

  private static final Category
cat=Category.getInstance(genericLog4JServlet.class.getName());

  public void init() throws javax.servlet.ServletException
{

  ServletContext context=getServletContext();

  /**
  * Get the Log4J settings and the logging paramters
  */
 try
  {
String strLogSetting
=(String)this.getInitParameter("Log4JFileSetting");

PropertyConfigurator.configure(context.getResource(strLogSetting));
  }
catch(java.net.MalformedURLException e){e.printStackTrace();}

}
}

-Original Message-
From: Eric Ma [mailto:[EMAIL PROTECTED]]
Sent: January 15, 2002 12:33 PM
To: [EMAIL PROTECTED]
Subject: How to use Log4j with a startup logging servlet


I want to use Log4J for logging exceptions thrown in a Struts-based web app.
After searching through this list, I found 2 common solutions:

1. Extend the Struts ActionServlet and override the init() method to set up
a Log4J Category.  Then in any custom Action class I can just call
servlet.Category.debug() (let's assume Category is a protected or public
variable).

2. Write a separate startup servlet and again set up LOG4J in the init()
method.  But my question is, how do I invoke this servlet from my custom
Action class?  Do I need to do a RequestDispatcher.forward() to the servlet
when an exception is thrown?  Then how do I get back to the page I am on to
display the error message?

Eric Ma


--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.




--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: How to use Log4j with a startup logging servlet

2002-01-15 Thread Jenkins, David

If you're using Tomcat 4.0.x then the documentation shows how to use a
servlet to configure Log4J. Essentially you create a normal servlet, slap it
in your web.xml and configure it to load on startup.
I do this in all my web apps and also use the same method to init Velocity.
Here's a sample web.xml entry

  
log4j-init
Log4jInit

  log4j-init-file
  WEB-INF/classes/log4j.properties

1
  

and the init method from the servlet

  public void init() throws ServletException {
String prefix =  getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
// if the log4j-init-file is not set, then no point in trying
if(file != null) {
  PropertyConfigurator.configure(prefix+file);
}
getServletContext().log("logging to: "+prefix+file);
  }



-Original Message-
From: Eric Ma [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 16 January 2002 6:33 a.m.
To: [EMAIL PROTECTED]
Subject: How to use Log4j with a startup logging servlet


I want to use Log4J for logging exceptions thrown in a Struts-based web app.
After searching through this list, I found 2 common solutions:

1. Extend the Struts ActionServlet and override the init() method to set up
a Log4J Category.  Then in any custom Action class I can just call
servlet.Category.debug() (let's assume Category is a protected or public
variable).

2. Write a separate startup servlet and again set up LOG4J in the init()
method.  But my question is, how do I invoke this servlet from my custom
Action class?  Do I need to do a RequestDispatcher.forward() to the servlet
when an exception is thrown?  Then how do I get back to the page I am on to
display the error message?

Eric Ma


--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



--
To unsubscribe, e-mail:

For additional commands, e-mail:



This message contains official information which is intended
for the use of the addressee(s) only.  If you are not the
intended recipient, please notify the sender immediately.
You should not further disseminate or copy this message
in any way.
*

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: How to use Log4j with a startup logging servlet

2002-01-15 Thread Thomas Eichberger

Hi,

I use Log4J, but don't understand your question exactly. I think it's 
easier than you think;-)

In my action classes and servlets and so on I have the usual line:

static Category cat = Category.getInstance( SuchAction.class.getName() );





in web.xml I have:

   
 log4j-init
 at.tanzforum.homepage.artists.Log4JInit

 
   log4j-init-file
   WEB-INF/classes/log4j.lcf
 

 1
   


as described in the documentation of Log4J (they explain there how to use 
Log4J with TomCat)


and finally I have that Servlet:

package at.tanzforum.homepage.artists;


import java.io.*;
import java.util.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;

import org.apache.log4j.*;



public class Log4JInit extends HttpServlet {

static Category cat = Category.getInstance( MainServlet.class.getName() );

   public void init()
   {
 String prefix =  getServletContext().getRealPath("/");
 String file = getInitParameter("log4j-init-file");
 // if the log4j-init-file is not set, then no point in trying
 if(file != null) {
   PropertyConfigurator.configure(prefix+file);
   cat.info( "Log4J configured by file " + prefix + file );
 }
   }

   public
   void doGet(HttpServletRequest req, HttpServletResponse res) {
   }
}




Ciao

Thomas










At 12:33 15.01.2002 -0500, you wrote:
>I want to use Log4J for logging exceptions thrown in a Struts-based web 
>app.  After searching through this list, I found 2 common solutions:
>
>1. Extend the Struts ActionServlet and override the init() method to set 
>up a Log4J Category.  Then in any custom Action class I can just call 
>servlet.Category.debug() (let's assume Category is a protected or public 
>variable).
>
>2. Write a separate startup servlet and again set up LOG4J in the init() 
>method.  But my question is, how do I invoke this servlet from my custom 
>Action class?  Do I need to do a RequestDispatcher.forward() to the 
>servlet when an exception is thrown?  Then how do I get back to the page I 
>am on to display the error message?
>
>Eric Ma
>
>
>--
>
>This e-mail may contain confidential and/or privileged information. If you 
>are not the intended recipient (or have received this e-mail in error) 
>please notify the sender immediately and destroy this e-mail. Any 
>unauthorized copying, disclosure or distribution of the material in this 
>e-mail is strictly forbidden.
>
>
>
>--
>To unsubscribe, e-mail:   
>For additional commands, e-mail: 

Thomas Eichberger - Software und Schulungen - Spezialisiert auf Java
A-1230 WIEN, Endresstr. 103/3
phone/box/fax: 01-8861685 Web: www.java.at E-Mail: [EMAIL PROTECTED]
"Every job is a self-portrait of the person who did it. Autograph yours 
with excellence."
"For every complex question there is an answer that is clear, simple and wrong."


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: How to use Log4j with a startup logging servlet

2002-01-15 Thread McDowell, Mark

I use method 2, but it doesn't require a call into that servlet.  I just use
it to initialize log4j.  After this servlet loads, I just call log4j object
methods, and it works.  I believe (someone correct me if I'm wrong) that the
servlet loads in the same JVM, so you have access to its objects in the
other servlets...

Mark

-Original Message-
From: Eric Ma [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 15, 2002 11:33 AM
To: [EMAIL PROTECTED]
Subject: How to use Log4j with a startup logging servlet


I want to use Log4J for logging exceptions thrown in a Struts-based web app.
After searching through this list, I found 2 common solutions:

1. Extend the Struts ActionServlet and override the init() method to set up
a Log4J Category.  Then in any custom Action class I can just call
servlet.Category.debug() (let's assume Category is a protected or public
variable).

2. Write a separate startup servlet and again set up LOG4J in the init()
method.  But my question is, how do I invoke this servlet from my custom
Action class?  Do I need to do a RequestDispatcher.forward() to the servlet
when an exception is thrown?  Then how do I get back to the page I am on to
display the error message?

Eric Ma


--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



--
To unsubscribe, e-mail:

For additional commands, e-mail:


--
To unsubscribe, e-mail:   
For additional commands, e-mail: