[CalendarServer-changes] [4360] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 18 17:53:08 PDT 2009
Revision: 4360
http://trac.macosforge.org/projects/calendarserver/changeset/4360
Author: wsanchez at apple.com
Date: 2009-06-18 17:53:08 -0700 (Thu, 18 Jun 2009)
Log Message:
-----------
Implement new extended logging hooks
Modified Paths:
--------------
CalendarServer/trunk/conf/caldavd-test.plist
CalendarServer/trunk/twistedcaldav/accesslog.py
CalendarServer/trunk/twistedcaldav/config.py
CalendarServer/trunk/twistedcaldav/extensions.py
CalendarServer/trunk/twistedcaldav/method/report.py
CalendarServer/trunk/twistedcaldav/method/report_multiget.py
Added Paths:
-----------
CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.method.report.patch
Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/conf/caldavd-test.plist 2009-06-19 00:53:08 UTC (rev 4360)
@@ -321,8 +321,6 @@
<string>logs/access.log</string>
<key>RotateAccessLog</key>
<false/>
- <key>MoreAccessLogData</key>
- <true/>
<!-- Server activity log -->
<key>ErrorLogFile</key>
Added: CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.method.report.patch
===================================================================
--- CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.method.report.patch (rev 0)
+++ CalendarServer/trunk/lib-patches/Twisted/twisted.web2.dav.method.report.patch 2009-06-19 00:53:08 UTC (rev 4360)
@@ -0,0 +1,34 @@
+Index: twisted/web2/dav/method/report.py
+===================================================================
+--- twisted/web2/dav/method/report.py (revision 26969)
++++ twisted/web2/dav/method/report.py (working copy)
+@@ -94,8 +94,9 @@
+ namespace = doc.root_element.namespace
+ name = doc.root_element.name
+
++ ok = string.ascii_letters + string.digits + "_"
++
+ def to_method(s):
+- ok = string.ascii_letters + string.digits + "_"
+ out = []
+ for c in s:
+ if c in ok:
+@@ -105,10 +106,17 @@
+ return "report_" + "".join(out)
+
+ if namespace:
+- method_name = to_method(namespace + "_" + name)
++ method_name = to_method("_".join((namespace, name)))
++
++ if namespace == davxml.dav_namespace:
++ request.submethod = "DAV:" + name
++ else:
++ request.submethod = "{%s}%s" % (namespace, name)
+ else:
+ method_name = to_method(name)
+
++ request.submethod = name
++
+ try:
+ method = getattr(self, method_name)
+
Modified: CalendarServer/trunk/twistedcaldav/accesslog.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/accesslog.py 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/twistedcaldav/accesslog.py 2009-06-19 00:53:08 UTC (rev 4360)
@@ -69,11 +69,7 @@
request = eventDict['request']
response = eventDict['response']
loginfo = eventDict['loginfo']
- firstLine = '%s %s HTTP/%s' %(
- request.method,
- request.uri.replace('"', '%22'),
- '.'.join([str(x) for x in request.clientproto]))
-
+
# Try to determine authentication and authorization identifiers
uid = "-"
if hasattr(request, "authnUser"):
@@ -103,28 +99,51 @@
uid = '"%s as %s"' % (uidn, uidz,)
else:
uid = uidn
-
- format_str = '%s - %s [%s] "%s" %s %d "%s" "%s" [%.1f ms]'
- format_data = (
- request.remoteAddr.host,
- uid,
- self.logDateString(
- response.headers.getHeader('date', 0)),
- firstLine,
- response.code,
- loginfo.bytesSent,
- request.headers.getHeader('referer', '-'),
- request.headers.getHeader('user-agent', '-'),
- (time.time() - request.initTime) * 1000,
+
+ if hasattr(request, "submethod"):
+ method = "%s(%s)" % (request.method, request.submethod)
+ else:
+ method = request.method
+
+ # Standard Apache access log fields
+ format = (
+ '%(host)s - %(uid)s [%(date)s]'
+ ' "%(method)s %(uri)s HTTP/%(protocolVersion)s"'
+ ' %(statusCode)s %(bytesSent)d'
+ ' "%(referer)s" "%(userAgent)s"'
)
- if config.MoreAccessLogData:
- format_str += ' [%s %s]'
- format_data += (
- request.serverInstance,
- request.chanRequest.channel.factory.outstandingRequests,
- )
- self.logMessage(format_str % format_data)
+ if config.EnableExtendedAccessLog:
+ formats = [
+ format,
+ # Performance monitoring extensions
+ 'i=%(serverInstance)d t=%(timeSpent).1fms or=%(outstandingRequests)d',
+ ]
+ if hasattr(request, "extendedLogItems"):
+ for k, v in request.extendedLogItems.iteritems():
+ v = str(v)
+ if " " in v:
+ v = '"%s"' % (v,)
+ formats.append("%s=%s" % (k, v.replace('"', "%22")))
+ format = " ".join(formats)
+
+ formatArgs = {
+ "host" : request.remoteAddr.host,
+ "uid" : uid,
+ "date" : self.logDateString(response.headers.getHeader('date', 0)),
+ "method" : method,
+ "uri" : request.uri.replace('"', "%22"),
+ "protocolVersion" : ".".join(str(x) for x in request.clientproto),
+ "statusCode" : response.code,
+ "bytesSent" : loginfo.bytesSent,
+ "referer" : request.headers.getHeader("referer", "-"),
+ "userAgent" : request.headers.getHeader("user-agent", "-"),
+ "serverInstance" : request.serverInstance,
+ "timeSpent" : (time.time() - request.initTime) * 1000,
+ "outstandingRequests" : request.chanRequest.channel.factory.outstandingRequests,
+ }
+ self.logMessage(format % formatArgs)
+
elif "overloaded" in eventDict:
overloaded = eventDict.get("overloaded")
format_str = '%s - - [%s] "???" 503 0 "-" "-" [0.0 ms]'
Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/twistedcaldav/config.py 2009-06-19 00:53:08 UTC (rev 4360)
@@ -183,8 +183,8 @@
"ErrorLogFile" : "/var/log/caldavd/error.log", # Server activity log
"ServerStatsFile": "/var/run/caldavd/stats.plist",
"PIDFile" : "/var/run/caldavd.pid",
- "RotateAccessLog" : False,
- "MoreAccessLogData" : True,
+ "RotateAccessLog" : False,
+ "EnableExtendedAccessLog" : True,
"DefaultLogLevel" : "",
"LogLevels" : {},
Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/twistedcaldav/extensions.py 2009-06-19 00:53:08 UTC (rev 4360)
@@ -61,6 +61,7 @@
from twistedcaldav.util import submodule, Alternator, printTracebacks
from twistedcaldav.directory.sudo import SudoDirectoryService
from twistedcaldav.directory.directory import DirectoryService
+from twistedcaldav.method.report import http_REPORT
log = Logger()
@@ -495,6 +496,9 @@
return super(DAVResource, self).http_ACL(request)
+ http_REPORT = http_REPORT
+
+
@inlineCallbacks
def findChildrenFaster(self, depth, request, okcallback, badcallback, names, privileges, inherited_aces):
"""
Modified: CalendarServer/trunk/twistedcaldav/method/report.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/report.py 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/twistedcaldav/method/report.py 2009-06-19 00:53:08 UTC (rev 4360)
@@ -72,7 +72,22 @@
namespace = doc.root_element.namespace
name = doc.root_element.name
- def to_method(s):
+ if namespace:
+ if namespace == davxml.dav_namespace:
+ request.submethod = "DAV:" + name
+ elif namespace == caldavxml.caldav_namespace:
+ request.submethod = "CalDAV:" + name
+ else:
+ request.submethod = "{%s}%s" % (namespace, name)
+ else:
+ request.submethod = name
+
+ def to_method(namespace, name):
+ if namespace:
+ s = "_".join((namespace, name))
+ else:
+ s = name
+
ok = string.ascii_letters + string.digits + "_"
out = []
for c in s:
@@ -82,10 +97,7 @@
out.append("_")
return "report_" + "".join(out)
- if namespace:
- method_name = to_method(namespace + "_" + name)
- else:
- method_name = to_method(name)
+ method_name = to_method(namespace, name)
try:
method = getattr(self, method_name)
Modified: CalendarServer/trunk/twistedcaldav/method/report_multiget.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/report_multiget.py 2009-06-18 16:47:34 UTC (rev 4359)
+++ CalendarServer/trunk/twistedcaldav/method/report_multiget.py 2009-06-19 00:53:08 UTC (rev 4360)
@@ -62,7 +62,16 @@
propertyreq = multiget.property
resources = multiget.resources
+
+ if not hasattr(request, "extendedLogItems"):
+ request.extendedLogItems = {}
+ request.extendedLogItems["rcount"] = len(resources)
+ # Check size of results is within limit
+ if len(resources) > max_number_of_multigets:
+ log.err("Too many results in multiget report: %d" % len(resources))
+ raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, davxml.NumberOfMatchesWithinLimits()))
+
if propertyreq.qname() == ("DAV:", "allprop"):
propertiesForResource = report_common.allPropertiesForResource
@@ -80,11 +89,6 @@
else:
raise AssertionError("We shouldn't be here")
- # Check size of results is within limit
- if len(resources) > max_number_of_multigets:
- log.err("Too many results in multiget report: %d" % len(resources))
- raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, davxml.NumberOfMatchesWithinLimits()))
-
"""
Three possibilities exist:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090618/dee0985b/attachment-0001.html>
More information about the calendarserver-changes
mailing list