juergen     2003/08/14 03:13:08

  Modified:    src/webdav/server/org/apache/slide/webdav/filter
                        LogFilter.java
  Log:
  made te filter more multi-user stable.
  
  Revision  Changes    Path
  1.4       +35 -40    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/filter/LogFilter.java
  
  Index: LogFilter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/filter/LogFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LogFilter.java    28 Feb 2003 12:50:08 -0000      1.3
  +++ LogFilter.java    14 Aug 2003 10:13:08 -0000      1.4
  @@ -92,7 +92,7 @@
    * @version $Revision$
    */
   public class LogFilter implements Filter {
  -    
  +
       FilterConfig config;
       ServletContext context;
       String logFormat = "%t, %p, %m, %s \"%l\", %i, %u";
  @@ -106,18 +106,7 @@
       String dateTimePattern = "dd-MMM-yyyy HH:mm:ss";
   
       // log elements
  -    String thread;
  -    String datetime;
  -    String method;
  -    String uri;
  -    String path;
  -    int status;
  -    String message;
  -    String principal;
  -    String detail;
  -    String contentlength;
  -    
  -    
  +
       /**
        * Interface implementation
        *
  @@ -130,7 +119,7 @@
           this.config = config;
           this.context = config.getServletContext();
           this.df = new SimpleDateFormat( dateTimePattern );
  -        
  +
           // get the init parms
           String p;
           p = config.getInitParameter( "logFormat" );
  @@ -155,7 +144,7 @@
               catch (IOException e) {}
           }
       }
  -    
  +
       /**
        * Interface implementation
        *
  @@ -170,37 +159,38 @@
       public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {
           XHttpServletRequestFacade req = new 
XHttpServletRequestFacade((HttpServletRequest)request);
           XHttpServletResponseFacade resp = new 
XHttpServletResponseFacade((HttpServletResponse)response);
  -        long b = System.currentTimeMillis();
  +        long start = System.currentTimeMillis();
   
           // incomming
  -        thread = Thread.currentThread().getName();
  -        datetime = df.format( new Date() );
  -        method = req.getMethod();
  -        uri = req.getRequestURI();
  -        path = req.getServletPath();
  +        String thread = Thread.currentThread().getName();
  +        String datetime = df.format( new Date() );
  +        String method = req.getMethod();
  +        String uri = req.getRequestURI();
  +        String path = req.getServletPath();
           if( "".equals(path) )
               path = "/";
           Principal p = req.getUserPrincipal();
  -        principal = (p != null ? p.getName() : "");
  -        contentlength = req.getHeader( "Content-Length" );
  +        String principal = (p != null ? p.getName() : "");
  +        String contentlength = req.getHeader( "Content-Length" );
           if( contentlength == null )
               contentlength = "-";
  -        
  +
           // next please!
           chain.doFilter( req, resp );
   
           // way back
  -        status = resp.getStatus();
  -        message = WebdavStatus.getStatusText(status);
  -        detail = resp.getStatusText();
  +        int status = resp.getStatus();
  +        String message = WebdavStatus.getStatusText(status);
  +        String detail = resp.getStatusText();
           if( detail == null || "".equals(detail) )
               detail = message;
  -        
  -        
  -        long a = System.currentTimeMillis();
  -        logLine( req, resp, (a-b) );
  +
  +
  +        long end = System.currentTimeMillis();
  +        logLine( (end-start), status, thread, method, datetime, uri, path, 
contentlength, principal,
  +               message, detail);
       }
  -    
  +
       /**
        * Log one line.
        *
  @@ -211,8 +201,13 @@
        * @throws   IOException
        *
        */
  -    private void logLine( XHttpServletRequestFacade req, XHttpServletResponseFacade 
resp, long elapsed ) throws IOException {
  -        
  +    private void logLine(long elapsed, int status,
  +                        String thread, String method, String datetime, String uri,
  +                         String path, String contentlength, String principal,
  +                        String message, String detail)
  +        throws IOException
  +    {
  +
           StringBuffer b = new StringBuffer( logFormat );
           int i;
           i = b.toString().indexOf("%T");
  @@ -237,7 +232,7 @@
           if( i >= 0 ) b.replace( i, i+2, uri );
           i = b.toString().indexOf("%x");
           if( i >= 0 ) b.replace( i, i+2, contentlength );
  -        
  +
           if( outputToConsole )
               System.out.println( b.toString() );
           if( outputToServletLog )
  @@ -248,7 +243,7 @@
               fout.flush();
           }
       }
  -    
  +
       /**
        * Interface implementation.
        *
  
  
  

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

Reply via email to