Code

safer logging from HTTP server (sf bug 896917
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sun, 15 Feb 2004 21:44:02 +0000 (21:44 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sun, 15 Feb 2004 21:44:02 +0000 (21:44 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2088 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/scripts/roundup_server.py

index 233b45dfb11d5ecfbf67b9d62fb51bee216eb24e..490c048eef474707dfc24ccc7925d62c4bfb787b 100644 (file)
@@ -86,6 +86,7 @@ Fixed:
 - use supplied content-type on file uploads before trying filename)
 - fixed roundup-reminder script to use default schema (thanks Klamer Schutte)
 - fixed edit action / parsePropsFromForm to handle index-page edits better
+- safer logging from HTTP server (sf bug 896917)
 
 
 2003-12-17 0.6.4
index 6f58a60ca3dd2fd71f6710b451de0aa2a613ad07..c40a71c02b7616c8be4fc98bfe74103cf3f737c8 100644 (file)
@@ -17,7 +17,7 @@
 
 """Command-line script that runs a server over roundup.cgi.client.
 
-$Id: roundup_server.py,v 1.37 2004-02-11 23:55:10 richard Exp $
+$Id: roundup_server.py,v 1.38 2004-02-15 21:44:02 richard Exp $
 """
 __docformat__ = 'restructuredtext'
 
@@ -70,6 +70,17 @@ AoFAtVo1m825XO7hSODOYrH4kHbxxGAwwODBGI/H6DBs5LNara7yl8slGjIcDsHpdrunU6PRCAP2
 r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo
 '''.strip()))
 
+class RoundupHTTPServer(SafeLogging, BaseHTTPServer.HTTPServer):
+    def log_message(self, format, *args):
+        ''' Try to use the logging package, otherwise *safely* log to
+            stderr.
+        '''
+        try:
+            BaseHTTPServer.HTTPServer.log_message(self, format, *args)
+        except IOError:
+            # stderr is no longer viable, we can't log
+            pass
+
 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     TRACKER_HOMES = TRACKER_HOMES
     ROUNDUP_USER = ROUNDUP_USER
@@ -229,8 +240,7 @@ else:
 
     SvcShutdown = "ServiceShutdown"
 
-    class RoundupService(win32serviceutil.ServiceFramework,
-            BaseHTTPServer.HTTPServer):
+    class RoundupService(win32serviceutil.ServiceFramework, RoundupHTTPServer):
         ''' A Roundup standalone server for Win32 by Ewout Prangsma
         '''
         _svc_name_ = "Roundup Bug Tracker"
@@ -242,7 +252,7 @@ else:
                 # appending, unbuffered
                 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0)
             win32serviceutil.ServiceFramework.__init__(self, args)
-            BaseHTTPServer.HTTPServer.__init__(self, self.address, 
+            RoundupHTTPServer.__init__(self, self.address, 
                 RoundupRequestHandler)
 
             # Create the necessary NT Event synchronization objects...
@@ -435,7 +445,7 @@ def run(port=PORT, success_message=None):
         # 1024 if started as root
         address = (hostname, port)
         try:
-            httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
+            httpd = RoundupHTTPServer(address, RoundupRequestHandler)
         except socket.error, e:
             if e[0] == errno.EADDRINUSE:
                 raise socket.error, \