Annotation of java/classes/org/w3c/jigsaw/http/ExtendedCommonLogger.java, revision 1.5
1.1 ylafon 1: // ExtendedCommonLogger.java
1.5 ! ylafon 2: // $Id: ExtendedCommonLogger.java,v 1.4 2000/02/25 10:19:07 ylafon Exp $
1.1 ylafon 3: // (c) COPYRIGHT MIT and INRIA, 1999.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package org.w3c.jigsaw.http ;
7:
8: import java.io.* ;
9: import java.util.Date ;
10:
11: import org.w3c.jigsaw.daemon.*;
12: import org.w3c.jigsaw.auth.AuthFilter;
13: import org.w3c.util.*;
14:
15: /**
16: * The ExtendedCommonLogger class implements the abstract Logger class.
17: * It just rotates the log every month and use the extended log format
18: * @see org.w3c.jigsaw.http.CommonLogger
19: */
20:
21:
22: public class ExtendedCommonLogger extends CommonLogger {
23:
24: private byte msgbuf[] = null ;
25:
26: /**
27: * Log the given HTTP transaction.
28: * This is shamelessly slow.
29: */
30:
31: public void log (Request request, Reply reply, int nbytes, long duration) {
32: Client client = request.getClient() ;
33: String entry = null ;
34: long date = reply.getDate();
35: // Compute the time zone offset, first call only.
36: if ( tz == -1 ) {
37: tz = new Date().getTimezoneOffset();
38: }
1.5 ! ylafon 39: Date now;
! 40: if (date < 0 ) {
! 41: now = new Date((new Date()).getTime() + tz*60*1000);
! 42: } else {
! 43: now = new Date(date + (tz*60*1000));
! 44: }
1.1 ylafon 45:
1.4 ylafon 46: if (rotateLevel > 0) {
47: checkLogFile(now);
1.1 ylafon 48: }
1.4 ylafon 49:
1.1 ylafon 50: String user = (String) request.getState(AuthFilter.STATE_AUTHUSER);
51:
52: entry = client.getInetAddress().getHostAddress()
53: + " " + "-" // user name
54: + " " + ((user == null ) ? "-" : user) // auth user name
55: + ((now.getDate() < 10) ? " [0" : " [")
56: + (now.getDate() // current date
57: + "/" + monthnames[now.getMonth()]
58: + "/" + (now.getYear() + 1900)
59: + ((now.getHours() < 10)
60: ? (":0" + now.getHours())
61: : (":" + now.getHours()))
62: + ((now.getMinutes() < 10)
63: ? (":0" + now.getMinutes())
64: : (":" + now.getMinutes()))
65: + ((now.getSeconds() < 10)
66: ? (":0" + now.getSeconds())
67: : (":" + now.getSeconds()))
1.5 ! ylafon 68: + " +0]")
1.1 ylafon 69: + " \"" + request.getMethod() // request line
70: + " " + request.getURL()
71: + " " + request.getVersion()
72: + "\" " + reply.getStatus() // reply status
73: + " " + nbytes // # of emited bytes
1.2 ylafon 74: + " \"" +
1.3 ylafon 75: ((request.getReferer() == null) ? "-" : request.getReferer())
1.2 ylafon 76: + "\"" // the referer (ext log)
77: + " \"" +
1.3 ylafon 78: ((request.getUserAgent() == null) ? "-" : request.getUserAgent())
1.2 ylafon 79: + "\"" // User agent
1.1 ylafon 80: + "\n" ;
81: logmsg (entry) ;
82: }
83:
84: /**
85: * Construct a new Logger instance.
86: */
87:
88: ExtendedCommonLogger () {
89: this.msgbuf = new byte[128] ;
90: }
91:
92: }
Webmaster