Index: cgi.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/cgi.py,v retrieving revision 1.80 diff -u -r1.80 cgi.py --- cgi.py 14 Aug 2004 15:39:34 -0000 1.80 +++ cgi.py 6 Dec 2004 04:00:26 -0000 @@ -40,6 +40,7 @@ import mimetools import rfc822 import UserDict +import logging from StringIO import StringIO __all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict", @@ -54,6 +55,7 @@ logfile = "" # Filename to log to, if not empty logfp = None # File object to log to, if not None +logger = None def initlog(*allargs): """Write a log message, if there is a log file. @@ -78,28 +80,24 @@ send an error message). """ - global logfp, log + global logfp, log, logger if logfile and not logfp: try: logfp = open(logfile, "a") except IOError: pass - if not logfp: - log = nolog - else: - log = dolog - log(*allargs) -def dolog(fmt, *args): - """Write a log message to the log file. See initlog() for docs.""" - logfp.write(fmt%args + "\n") - -def nolog(*allargs): - """Dummy function, assigned to log when logging is disabled.""" - pass + logger = logging.getLogger('cgi') -log = initlog # The current logging function + if logfp: + handler = logging.StreamHandler(logfp) + logger.addHandler(handler) + logger.setLevel(logging.INFO) + log = logger.info + log(*allargs) + +log = initlog # The current logging function # Parsing functions # =================