Skip to content

Commit 77214dd

Browse files
author
Richard Jones
committed
safer logging from HTTP server ([SF#896917]
1 parent 65fb2ba commit 77214dd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Fixed:
8686
- use supplied content-type on file uploads before trying filename)
8787
- fixed roundup-reminder script to use default schema (thanks Klamer Schutte)
8888
- fixed edit action / parsePropsFromForm to handle index-page edits better
89+
- safer logging from HTTP server (sf bug 896917)
8990

9091

9192
2003-12-17 0.6.4

roundup/scripts/roundup_server.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.37 2004-02-11 23:55:10 richard Exp $
20+
$Id: roundup_server.py,v 1.38 2004-02-15 21:44:02 richard Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -70,6 +70,17 @@
7070
r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo
7171
'''.strip()))
7272

73+
class RoundupHTTPServer(SafeLogging, BaseHTTPServer.HTTPServer):
74+
def log_message(self, format, *args):
75+
''' Try to use the logging package, otherwise *safely* log to
76+
stderr.
77+
'''
78+
try:
79+
BaseHTTPServer.HTTPServer.log_message(self, format, *args)
80+
except IOError:
81+
# stderr is no longer viable, we can't log
82+
pass
83+
7384
class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
7485
TRACKER_HOMES = TRACKER_HOMES
7586
ROUNDUP_USER = ROUNDUP_USER
@@ -229,8 +240,7 @@ def error():
229240

230241
SvcShutdown = "ServiceShutdown"
231242

232-
class RoundupService(win32serviceutil.ServiceFramework,
233-
BaseHTTPServer.HTTPServer):
243+
class RoundupService(win32serviceutil.ServiceFramework, RoundupHTTPServer):
234244
''' A Roundup standalone server for Win32 by Ewout Prangsma
235245
'''
236246
_svc_name_ = "Roundup Bug Tracker"
@@ -242,7 +252,7 @@ def __init__(self, args):
242252
# appending, unbuffered
243253
sys.stdout = sys.stderr = open(LOGFILE, 'a', 0)
244254
win32serviceutil.ServiceFramework.__init__(self, args)
245-
BaseHTTPServer.HTTPServer.__init__(self, self.address,
255+
RoundupHTTPServer.__init__(self, self.address,
246256
RoundupRequestHandler)
247257

248258
# Create the necessary NT Event synchronization objects...
@@ -435,7 +445,7 @@ def run(port=PORT, success_message=None):
435445
# 1024 if started as root
436446
address = (hostname, port)
437447
try:
438-
httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
448+
httpd = RoundupHTTPServer(address, RoundupRequestHandler)
439449
except socket.error, e:
440450
if e[0] == errno.EADDRINUSE:
441451
raise socket.error, \

0 commit comments

Comments
 (0)