From a9baa6bd0da0cd1b652f0f529857bbf608855cc9 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Thu, 2 Jul 1998 19:34:57 +0000 Subject: Use the new Mailman.Logging package to provide better logging on errors. Now all tracebacks get sent to the user as HTML *and* logged to logs/error, although the format of the output is slightly different (not HTML in the latter case). Some rearranging of code, simplification, etc. --- scripts/driver | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/scripts/driver b/scripts/driver index fc2b59a4e..55cd85090 100644 --- a/scripts/driver +++ b/scripts/driver @@ -51,18 +51,16 @@ def run_main(): # insert the relative path to the parent of the Mailman package # directory, so we can pick up the Utils module import os + # sys gets imported at module level below sys.path.insert(0, os.pardir) # map stderr to a logger, if possible - import Mailman.Utils - try: - sys.stderr = Utils.StampedLogger('error', label='admin', - manual_reprime=1, - nofail=0) - except: - # semi-bogus bare except means that if any problems in creating - # the logger occur, we should just use standard stderr - pass - # + from Mailman.Logging.StampedLogger import StampedLogger + from Mailman.Logging.MultiLogger import MultiLogger + logger = StampedLogger('error', + label='admin', + manual_reprime=1, + nofail=0) + multi = MultiLogger(sys.__stdout__, logger) # The name of the module to run is passed in argv[1]. What we # actually do is import the module named by argv[1] that lives in the # Mailman.Cgi package. That module must have a main() function, which @@ -80,12 +78,12 @@ def run_main(): # this is a valid way for the function to exit pass except: - print_traceback() - print_environment() + print_traceback(logger, multi) + print_environment(logger) -def print_traceback(): +def print_traceback(logger, multi): print """\ Content-type: text/html @@ -98,16 +96,20 @@ a description of what happened. Thanks!

Traceback:

 """
+    logger.write('[----- Traceback ------]\n')
     try:
         import traceback
-        traceback.print_exc(file=sys.stdout)
+        # in normal situation, this will get logged to the MultiLogger created
+        # above, which will write the data to both the real live stdout, and
+        # the StampedLogger
+        traceback.print_exc(file=multi)
     except:
-        print '[failed to get a traceback]'
+        multi.write('[failed to get a traceback]\n')
     print '\n\n
' -def print_environment(): +def print_environment(logger): try: import os print '''\ @@ -117,8 +119,10 @@ def print_environment(): Variable Value ''' + logger.write('[----- Environment Variables -----]\n') for varname, value in os.environ.items(): print '', varname, '', value, '' + logger.write('\t%s: %s\n' % (varname, value)) print '' except: print '


[environment variables are not available]' @@ -126,13 +130,12 @@ def print_environment(): try: import sys - # cache so we can undo this, even though it's probably not strictly - # necessary since the script is exiting soon anyway - stderr = sys.stderr try: run_main() finally: - sys.stderr = stderr + # this is probably not strictly necessary since the script is exiting + # soon anyway + sys.stderr = sys.__stderr__ except: # Jeez, we couldn't even import sys, or sys didn't have a stderr # attribute! -- cgit v1.3.1