You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by SCOTT FARQUHAR <SC...@sydneywater.com.au> on 2001/05/07 05:57:57 UTC
Re: log4j with jsp's
1& 2 are involving init-parameters.
Instead of hard-coding in the filename that I would use, I pass the filename as a parameter to the servlet. These parameters are stored in a text-file, or in the server config, depending on which server you have.
3) What you are after is a different appender for each program. ie:
log4j.category.program_a=DEBUG, A1
log4j.category.program_b=DEBUG, A2
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=c:/temp/log_a.txt
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=c:/temp/log_b.txt
4) You are probably best heading over to http://java.sun.com/jsp/ for information about jsp's and servlets. Jsp's are compiled into servlets, which are then used to process your request.
I've brought this conversation back on list, for archiving purposes.
Scott
>>> Marc Harrington <ma...@nebula.ie> 05/04/01 02:52am >>>
Hi Scott,
Thanks for replying to my mail .
Your code was very helpfull.
I have a few questions for you.
Sorry if some of them may sound a bit dumb ( I have little experience of log4j ) .
1)How do i pass the fully-qualified filename to the servlet ?
2) To get your servlet code working under Weblogic I had to comment out the following line:
log4jProps = config.getInitParameter("C:/weblogic/myserver/public_html/sort2.lcf");
and replaced the line with
log4jProps = "C:/weblogic/myserver/public_html/sort2.lcf";
Do you know a better solution ?
3) I want to get Log4j working so that when program_a runs it prints out to log_a.txt and when program_b runs it prints out to log_b.txt ( program_a and program_b are running concurrently ) I read that log4j has this capability built in , but i can't find out how to implement this.
4) If you have time , can you briefly explain how the jsp and servlet interact?
I would appreciate any code you can send me.
Thanks a million,
Marc Harrington
MIME:SCOTT.FARQUHAR@sydneywater.com.au on 05/03/2001 02:21:24 AM
To: Marc Harrington@nebula
cc:
Subject: Re: log4j with jsp's
Sure.
What I do is have a servlet that loads the property configurator from a init parameter, and then each jsp has in include file that sets up logging.
Here is the servlet:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
public class StartLogging extends HttpServlet
{
static Category cat = Category.getInstance(StartLogging.class.getName()); public void init(ServletConfig config) throws ServletException
{
String log4jProps = config.getInitParameter("log4j.properties");
System.out.println("Starting Logging using properties file: " + log4jProps);
PropertyConfigurator.configure(log4jProps);
cat.info("StartLogging Servlet started successfully using props: " + log4jProps);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here are the appropriate lines in the jsp:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<%@ page import="org.apache.log4j.Category" %>
<% Category log = Category.getInstance(request.getServletPath()); %>
<% log.debug("this is from general_page_template.jsp");
log.info("this is from general_page_template.jsp");
log.warn("this is from general_page_template.jsp");
log.error("this is from general_page_template.jsp");
log.fatal("this is from general_page_template.jsp");
%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let me know how you go. Don't forget to pass the fully-qualified filename to the servlet.
Scott
>>> Marc Harrington <ma...@nebula.ie> 05/02/01 08:29pm >>>
Hi Scott,
After looking through the log4j mailing list history , I saw that you have used log4j with jsp's.
Could you possibily send me any jsp/java code you have as i'm having problems getting log4j working with jsp's.
Thanks
Marc Harrington
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org