[Zope-Checkins] CVS: Zope/lib/python/ZServer - DebugLogger.py:1.8.58.1
Fred L. Drake, Jr.
fred@zope.com
Thu, 30 Jan 2003 11:41:43 -0500
Update of /cvs-repository/Zope/lib/python/ZServer
In directory cvs.zope.org:/tmp/cvs-serv25439
Modified Files:
Tag: new-install-branch
DebugLogger.py
Log Message:
Update from the chrism-install-branch.
=== Zope/lib/python/ZServer/DebugLogger.py 1.8 => 1.8.58.1 ===
--- Zope/lib/python/ZServer/DebugLogger.py:1.8 Wed Aug 14 17:16:50 2002
+++ Zope/lib/python/ZServer/DebugLogger.py Thu Jan 30 11:41:40 2003
@@ -11,56 +11,47 @@
#
##############################################################################
-import time, thread
+"""
+Logs debugging information about how ZServer is handling requests
+and responses. This log can be used to help locate troublesome requests.
-class DebugLogger:
- """
- Logs debugging information about how ZServer is handling requests
- and responses. This log can be used to help locate troublesome requests.
+The format of a log message is:
- The format is:
+ <code> <request id> <time> <data>
- <code> <request id> <time> <data>
+where:
- where:
+ <code> is B for begin, I for received input, A for received output,
+ E for sent output.
- 'code' is B for begin, I for received input, A for received output,
- E for sent output.
+ <request id> is a unique request id.
- 'request id' is a unique request id.
+ <time> is the local time in ISO 6801 format.
- 'time' is the time in localtime ISO format.
+ <data> is the HTTP method and the PATH INFO for B, the size of the
+ input for I, the HTTP status code and the size of the output for
+ A, or nothing for E.
+"""
- 'data' is the HTTP method and the PATH INFO for B, the size of the input
- for I, the HTTP status code and the size of the output for A, or
- nothing for E.
+import time
+import logging
- Note: This facility will be probably be adapted to the zLOG framework.
- """
+from zLOG.BaseLogger import BaseLogger
- def __init__(self, filename):
- self.filename = filename
- self.file=open(filename, 'a+b')
- l=thread.allocate_lock()
- self._acquire=l.acquire
- self._release=l.release
- self.log('U', '000000000', 'System startup')
- def reopen(self):
- self.file.close()
- self.file=open(self.filename, 'a+b')
- self.log('U', '000000000', 'Logfile reopened')
+class DebugLogger(BaseLogger):
+
+ logger = logging.getLogger('trace')
def log(self, code, request_id, data=''):
- self._acquire()
- try:
- t=time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(time.time()))
- self.file.write(
- '%s %s %s %s\n' % (code, request_id, t, data)
- )
- self.file.flush()
- finally:
- self._release()
+ if not self.logger.handlers:
+ return
+ # Omitting the second parameter requires Python 2.2 or newer.
+ t = time.strftime('%Y-%m-%dT%H:%M:%S')
+ message = '%s %s %s %s' % (code, request_id, t, data)
+ self.logger.warn(message)
-def log(*args): pass
+debug_logger = DebugLogger()
+log = debug_logger.log
+reopen = debug_logger.reopen