velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luo, Frank" <Frank....@travelocity.com>
Subject RE: exception handling and logging from velocity tools best practice
Date Tue, 20 Jun 2006 15:46:55 GMT
I am using velocity as a rendering tool but implemented a "non-velocity"
logger as a "HandlerInterceptorAdapter". 

I think it is a better approach because it will catch exceptions even
when velocity fails to load, for example.

========================================================================
====================
public class PageRequestTracker
  extends HandlerInterceptorAdapter
{
  public boolean preHandle( HttpServletRequest request,
HttpServletResponse response, Object handler )
    throws Exception
  {
    PageRequestEvent event = new PageRequestEvent( request.getMethod(),
 
request.getRequestURI(),
 
WebUtils.getSessionId( request ),
 
request.getServletPath(),
 
request.getParameterMap(),
 
request.getRemoteAddr(),
 
request.getUserPrincipal() );

    EventRecordLogger.logRecord( event );
    return true;
  }

  public void afterCompletion( HttpServletRequest request,
                               HttpServletResponse response,
                               Object handler,
                               Exception ex ) throws Exception
  {
    PageResponseEvent event = new PageResponseEvent(
request.getMethod(),
 
request.getRequestURI(),
 
WebUtils.getSessionId( request ),
 
request.getServletPath(),
 
request.getParameterMap(),
 
request.getRemoteAddr(),
 
request.getUserPrincipal(),
                                                     ex );
    EventRecordLogger.logRecord( event );
  }
} 

-----Original Message-----
From: Townson, Chris [mailto:C.Townson@nature.com] 
Sent: Tuesday, June 20, 2006 5:36 AM
To: Velocity Users List
Subject: exception handling and logging from velocity tools best
practice

Hi,

I was wondering if there were any docs anywhere on recommended ways to
handle exceptions/logging in velocity tools.

I'm using VelocityViewServlet with a SimpleLog4JLogSystem and want a
nice, abstracted way for velocity tools (loaded via toolbox) to log
errors to whatever velocity.log is specified in velocity.properties
(whether or not that's SimpleLog4JLogSystem or not).

What's the best way to go about achieving that?

Cheers,

Chris

************************************************************************
********   
DISCLAIMER: This e-mail is confidential and should not be used by anyone
who is
not the original intended recipient. If you have received this e-mail in
error
please inform the sender and delete it from your mailbox or any other
storage
mechanism. Neither Macmillan Publishers Limited nor any of its agents
accept
liability for any statements made which are clearly the sender's own and
not
expressly made on behalf of Macmillan Publishers Limited or one of its
agents.
Please note that neither Macmillan Publishers Limited nor any of its
agents
accept any responsibility for viruses that may be contained in this
e-mail or
its attachments and it is your responsibility to scan the e-mail and 
attachments (if any). No contracts may be concluded on behalf of
Macmillan 
Publishers Limited or its agents by means of e-mail communication.
Macmillan 
Publishers Limited Registered in England and Wales with registered
number 785998 
Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS   
************************************************************************
********

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


Mime
View raw message