logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kirk Benson" <kirk.ben...@brokat.com>
Subject RE: JSPAppender?
Date Wed, 10 Jan 2001 14:23:33 GMT
I think you misunderstood my proposal.  Rather than coding

  Category x = Category.getInstance("hello");

The proposed code would be

  JspCategory x = JspCategory.getInstance(sessionID);

sessionID (or whatever identifies the client, a la NDC) is a unique string.
If a JspCategory exists in the pool, it is returned.  Otherwise, JspCategory
can call super.getInstance(sessionID) or use the factory class to get a new
Category object.  Therefore, the number of allocated Category objects equals
the high-water mark of simulataneous client sessions.

In any case, the log output would be merged with the HTML output of the JSP,
which might not be what is wanted.  To avoid this, the Appender might write
to a memory buffer (e.g., BodyContent) and then have the JSP output the
string contents at the end of the page.


-----Original Message-----
From: Ceki Gulcu [mailto:cgu@urbanet.ch]
Sent: Wednesday, January 10, 2001 8:57 AM
To: LOG4J Users Mailing List
Cc: Kirk Benson
Subject: RE: JSPAppender?


I think your proposal is misguided. First and foremost,
Category.getInstance will not create new instances when called with the
same name argument. For example,

Category x = Category.getInstance("hello");
Category y = Category.getInstance("hello");

The variables x and y refer to the same object. I guess the rest of the
proposal falls apart. Would you concur?

If your goal is to have a separate output target for each client request,
then IMHO log4j can deal with this pretty well. I suggest that you look at
the code of org/apache/log4j/net/SocketServer. (This is  new code
introduced in 1.0.) The main idea there is to define a separate hierarchy
per host.

Log4j defines all the plumbing for dealing with different
hierarchies.  However, it is your responsibility to tell log4j when to use
which hierarchy as log4j is not aware of your context. I hope this helps,

At 08:18 10.01.2001 -0500, you wrote:
>I'm new to log4j as well, but I've spent the past couple of days trying to
>getup to speed.  The problem you address is having a separate output target
>for each client request, and it appears to me that log4j's design is not
>up for this.
>To log output, you must have a Category object which you obtain with the
>getInstance method.  The instance must supply a category name string in
>order to get the object.  Since you want a separate instance for each web
>request, the name string needs to be unique to the request.  You could
>generate a name using a session id or Cookie.  Since Category instances are
>not capable of being destroyed, you would theoretically continue to create
>these instances for each web request until the JSP JVM runs out of memory.
>To route output to the JSP, you would need an Appender which writes its
>output to the Writer returned from HttpServletResponse.getWriter().
>Given the above, I think you could implement a workable solution as
>a) Extend Category to implement a pool of instances.  Override the
>getInstance method to return an object from the pool.  If the pool is empty
>use the CategoryFactory to get a new one.  Add a method such as free()
>your JSP would call to return the object to the pool.  This prevents using
>up memory.  You can look at the MyCategory class to see how to do most of
>b) Extend AppenderSkeleton to implement a JSP Appender.  The constructor
>would have the JSP output Writer as its parameter.  Add this Appender to
>custom Category object.
>c) Pass the Category instance within your JSP classes as opposed to coding
>the getInstance in each one.
>d) At the end of the JSP return the Category to the pool.  You can leave
>Appender "attached" to the Category for re-use.
>Since you will not be able to configure your Category or Appender via
>Properties or XML, you will have to code all of the configuration as well
>(e.g., Layout, Pattern, etc.)
>List members ... does this sound about right?
>-----Original Message-----
>From: Ceki Gulcu [mailto:cgu@urbanet.ch]
>Sent: Tuesday, January 09, 2001 6:16 PM
>To: LOG4J Users Mailing List
>Cc: tom.palmer@interpath.net
>Subject: Re: JSPAppender?
>I am no JSP/Servlet expert. I don't know if a general solution is feasible
>but I think a site specific solution can be easily written by emulating the
>SMTPAppender. Regards, Ceki
>At 17:02 09.01.2001 -0500, you wrote:
> >Just downloaded log4j and started using it for JSP/Servlet development -
> >very nice.  Question: has anyone implemented an output option that will
> >log back to the JSP-generated page?  I'd like to be able to setup the
> >log object in the page and then pass it to various utility classes.
> >When these classes write to the log, it ends up on the output page for
> >quick viewing.
> >
> >Thanks -
> >
> >--
> >Tom Palmer                                  Interpath Communications
> >Interactive Technologies Consulting         1700 Perimeter Park West
> >tom.palmer@interpath.net                    Morrisville, NC 27560
> >919-253-5937
> >919-253-6586 (fax)
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org

To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org

View raw message