KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > util > webloggers > W3CExtendedLogger


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.deliver.util.webloggers;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 /**
30  * The W3CExtendedLogger class is a class that writes down a request in the W3C Extended Log Format.
31  */

32
33 public class W3CExtendedLogger extends CommonLogger
34 {
35     /**
36      * Construct a new Logger instance.
37      */

38
39     public W3CExtendedLogger()
40     {
41     }
42
43     /**
44      * Logs the given request.
45      */

46
47     public synchronized void logRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, String JavaDoc pagePath, long duration)
48     {
49         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50         
51         sb.append(defaultValueIfNull(getCurrentDate("yyyy-MM-dd HH:mm:ss"))); //date + time
52
sb.append(" ");
53         sb.append(defaultValueIfNull(request.getRemoteAddr())); //c-ip
54
sb.append(" ");
55         sb.append(defaultValueIfNull(request.getRemoteUser())); //cs-username
56
sb.append(" ");
57         sb.append("W3SVC1"); //s-sitename
58
sb.append(" ");
59         sb.append(defaultValueIfNull(getHostName())); //s-computername
60
sb.append(" ");
61         sb.append(defaultValueIfNull(getHostAddress())); //s-ip
62
sb.append(" ");
63         sb.append(defaultValueIfNull("" + request.getServerPort())); //s-port
64
sb.append(" ");
65         sb.append(defaultValueIfNull(request.getMethod())); //cs-method
66
sb.append(" ");
67         sb.append(defaultValueIfNull(pagePath)); //cs-uri-stem (translated to our pagePath)
68
sb.append(" ");
69         sb.append(defaultValueIfNull(request.getQueryString())); //cs-uri-query
70
sb.append(" ");
71         sb.append("-"); //Status - we can't tell from here //sc-status
72
sb.append(" ");
73         sb.append("-"); //Status - we can't tell from here //sc-win32-status
74
sb.append(" ");
75         sb.append(defaultValueIfNull("" + response.getBufferSize())); //sc-bytes
76
sb.append(" ");
77         sb.append(defaultValueIfNull(request.getHeader("Content-Length"))); //cs-bytes
78
sb.append(" ");
79         sb.append(defaultValueIfNull("" + duration)); //time-taken
80
sb.append(" ");
81         sb.append(defaultValueIfNull(request.getProtocol())); //cs-version
82
sb.append(" ");
83         sb.append(defaultValueIfNull(request.getRemoteHost())); //cs-host
84
sb.append(" ");
85         sb.append(defaultValueIfNull(request.getHeader("User-Agent"))); //cs(User-Agent)
86
sb.append(" ");
87         sb.append(defaultValueIfNull(request.getHeader("Cookie"))); //cs(Cookie)
88
sb.append(" ");
89         sb.append(defaultValueIfNull(request.getHeader("Referer"))); //cs(Referer)
90

91         writeRequest(getCurrentDate("yyyy-MM-dd"), sb.toString());
92     }
93
94
95 }
96
97
Popular Tags