[Checkins] SVN: zc.zservertracelog/branches/dev/src/zc/zservertracelog/tracelog.py Tried to add some error handling to avoid missing trace records.

Jim Fulton jim at zope.com
Sat Apr 28 09:40:46 EDT 2007


Log message for revision 74879:
  Tried to add some error handling to avoid missing trace records.
  

Changed:
  U   zc.zservertracelog/branches/dev/src/zc/zservertracelog/tracelog.py

-=-
Modified: zc.zservertracelog/branches/dev/src/zc/zservertracelog/tracelog.py
===================================================================
--- zc.zservertracelog/branches/dev/src/zc/zservertracelog/tracelog.py	2007-04-28 13:40:44 UTC (rev 74878)
+++ zc.zservertracelog/branches/dev/src/zc/zservertracelog/tracelog.py	2007-04-28 13:40:45 UTC (rev 74879)
@@ -50,6 +50,8 @@
         zope.server.http.httpserverchannel.HTTPServerChannel.handle_request(
             self, parser)
 
+
+status_match = re.compile('(\d+) (.*)').match
 class Server(wsgihttpserver.WSGIHTTPServer):
 
     channel_class = Channel
@@ -62,7 +64,7 @@
 
         def start_response(status, headers):
             # Prepare the headers for output
-            status, reason = re.match('([0-9]*) (.*)', status).groups()
+            status, reason = status_match(status).groups()
             task.setResponseStatus(status, reason)
             task.appendResponseHeaders(['%s: %s' % i for i in headers])
 
@@ -70,18 +72,29 @@
             return wsgihttpserver.fakeWrite
 
         # Call the application to handle the request and write a response
-        response = self.application(env, start_response)
-        length = [h.split(': ')[1].strip()
-                  for h in task.accumulated_headers
-                  if h.lower().startswith('content-length: ')]
-        if length:
-            length = length[0]
+        try:
+            response = self.application(env, start_response)
+        except Exception, v:
+            logger.info("A %s %s Error: %s", id(self), now(), v)
+            logger.info("E %s %s", id(self), now())
+            raise
         else:
-            length = '?'
-        logger.info("A %s %s %s %s", id(self), now(),
-                    task.status, length)
-        task.write(response)
-        logger.info("E %s %s", id(self), now())
+            length = [h.split(': ')[1].strip()
+                      for h in getattr(task, 'accumulated_headers', ())
+                      if h.lower().startswith('content-length: ')]
+            if length:
+                length = length[0]
+            else:
+                length = '?'
+            logger.info("A %s %s %s %s", id(self), now(),
+                        getattr(task, 'status', '?'), length)
+            try:
+                task.write(response)
+            except Exception, v:
+                logger.info("E %s %s Error: %s", id(self), now(), v)
+                raise
+            else:
+                logger.info("E %s %s", id(self), now())
 
 http = servertype.ServerType(
     Server,



More information about the Checkins mailing list