[CalendarServer-changes] [4156] CalendarServer/trunk/twext/web2/channel/http.py

source_changes at macosforge.org source_changes at macosforge.org
Sun May 3 10:10:22 PDT 2009


Revision: 4156
          http://trac.macosforge.org/projects/calendarserver/changeset/4156
Author:   cdaboo at apple.com
Date:     2009-05-03 10:10:20 -0700 (Sun, 03 May 2009)
Log Message:
-----------
Split request/response logging so that we can serialize the headers/bodies in the proper way in the log output.

Modified Paths:
--------------
    CalendarServer/trunk/twext/web2/channel/http.py

Modified: CalendarServer/trunk/twext/web2/channel/http.py
===================================================================
--- CalendarServer/trunk/twext/web2/channel/http.py	2009-05-03 16:51:58 UTC (rev 4155)
+++ CalendarServer/trunk/twext/web2/channel/http.py	2009-05-03 17:10:20 UTC (rev 4156)
@@ -103,17 +103,17 @@
             
     def __init__(self, channel, queued=0):
         
-        self.logData = [] if accounting.accountingEnabledForCategory("HTTP") else None
+        self.logData = ([], [],) if accounting.accountingEnabledForCategory("HTTP") else None
         super(HTTPLoggingChannelRequest, self).__init__(channel, queued)
         if self.logData is not None:
-            self.transport = HTTPLoggingChannelRequest.TransportLoggingWrapper(self.transport, self.logData)
+            self.transport = HTTPLoggingChannelRequest.TransportLoggingWrapper(self.transport, self.logData[1])
     
     def gotInitialLine(self, initialLine):
         
         if self.logData is not None:
             self.startTime = time.time()
-            self.logData.append(">>>> Request starting at: %.3f\r\n\r\n" % (self.startTime,))
-            self.logData.append("%s\r\n" % (initialLine,))
+            self.logData[0].append(">>>> Request starting at: %.3f\r\n\r\n" % (self.startTime,))
+            self.logData[0].append("%s\r\n" % (initialLine,))
         super(HTTPLoggingChannelRequest, self).gotInitialLine(initialLine)
 
     def lineReceived(self, line):
@@ -125,26 +125,26 @@
                 bits = line[14:].strip().split(" ")
                 if bits[0].lower() == "basic" and len(bits) == 2:
                     loggedLine = "%s %s %s" % (line[:14], bits[0], "X" * len(bits[1]))
-            self.logData.append("%s\r\n" % (loggedLine,))
+            self.logData[0].append("%s\r\n" % (loggedLine,))
         super(HTTPLoggingChannelRequest, self).lineReceived(line)
 
     def handleContentChunk(self, data):
         
         if self.logData is not None:
-            self.logData.append(data)
+            self.logData[0].append(data)
         super(HTTPLoggingChannelRequest, self).handleContentChunk(data)
         
     def handleContentComplete(self):
         
         if self.logData is not None:
             doneTime = time.time()
-            self.logData.append("\r\n\r\n>>>> Request complete at: %.3f (elapsed: %.1f ms)" % (doneTime, 1000 * (doneTime - self.startTime),))
+            self.logData[0].append("\r\n\r\n>>>> Request complete at: %.3f (elapsed: %.1f ms)" % (doneTime, 1000 * (doneTime - self.startTime),))
         super(HTTPLoggingChannelRequest, self).handleContentComplete()
 
     def writeHeaders(self, code, headers):
         if self.logData is not None:
             doneTime = time.time()
-            self.logData.append("\r\n\r\n<<<< Response sending at: %.3f (elapsed: %.1f ms)\r\n\r\n" % (doneTime, 1000 * (doneTime - self.startTime),))
+            self.logData[1].append("\r\n\r\n<<<< Response sending at: %.3f (elapsed: %.1f ms)\r\n\r\n" % (doneTime, 1000 * (doneTime - self.startTime),))
         super(HTTPLoggingChannelRequest, self).writeHeaders(code, headers)
 
     def finish(self):
@@ -153,7 +153,7 @@
 
         if self.logData is not None:
             doneTime = time.time()
-            self.logData.append("\r\n\r\n<<<< Response complete at: %.3f (elapsed: %.1f ms)\r\n" % (doneTime, 1000 * (doneTime - self.startTime),))
-            accounting.emitAccounting("HTTP", "all", "".join(self.logData))
+            self.logData[1].append("\r\n\r\n<<<< Response complete at: %.3f (elapsed: %.1f ms)\r\n" % (doneTime, 1000 * (doneTime - self.startTime),))
+            accounting.emitAccounting("HTTP", "all", "".join(self.logData[0]) + "".join(self.logData[1]))
 
 HTTPChannel.chanRequestFactory = HTTPLoggingChannelRequest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090503/f11aedff/attachment.html>


More information about the calendarserver-changes mailing list