Commit 5845a0b9 authored by Amos Latteier's avatar Amos Latteier

Changed tabs to spaces and added a flush to log writing.

parent 0dc69b1e
...@@ -86,48 +86,47 @@ ...@@ -86,48 +86,47 @@
import time, thread import time, thread
class DebugLogger: class DebugLogger:
""" """
Logs debugging information about how ZServer is handling requests Logs debugging information about how ZServer is handling requests
and responses. This log can be used to help locate troublesome requests. and responses. This log can be used to help locate troublesome requests.
The format 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, 'code' is B for begin, I for received input, A for received output,
E for sent output. E for sent output.
'request id' is a unique request id. 'request id' is a unique request id.
'time' is the time in GMT ISO format. 'time' is the time in GMT ISO format.
'data' is the HTTP method and the PATH INFO for B, the size of the input '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 for I, the HTTP status code and the size of the output for A, or
nothing for E. nothing for E.
Note: This facility will be probably be adapted to the zLOG framework. Note: This facility will be probably be adapted to the zLOG framework.
""" """
def __init__(self, filename): def __init__(self, filename):
self.file=open(filename, 'a+b') self.file=open(filename, 'a+b')
l=thread.allocate_lock() l=thread.allocate_lock()
self._acquire=l.acquire self._acquire=l.acquire
self._release=l.release self._release=l.release
def log(self, code, request_id, data=''): def log(self, code, request_id, data=''):
self._acquire() self._acquire()
try: try:
t=time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time())) t=time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time()))
self.file.write( self.file.write(
'%s %s %s %s\n' % (code, request_id, t, data) '%s %s %s %s\n' % (code, request_id, t, data)
) )
finally: self.file.flush()
self._release() finally:
self._release()
def log(*args): pass def log(*args): pass
\ No newline at end of file
...@@ -86,48 +86,47 @@ ...@@ -86,48 +86,47 @@
import time, thread import time, thread
class DebugLogger: class DebugLogger:
""" """
Logs debugging information about how ZServer is handling requests Logs debugging information about how ZServer is handling requests
and responses. This log can be used to help locate troublesome requests. and responses. This log can be used to help locate troublesome requests.
The format 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, 'code' is B for begin, I for received input, A for received output,
E for sent output. E for sent output.
'request id' is a unique request id. 'request id' is a unique request id.
'time' is the time in GMT ISO format. 'time' is the time in GMT ISO format.
'data' is the HTTP method and the PATH INFO for B, the size of the input '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 for I, the HTTP status code and the size of the output for A, or
nothing for E. nothing for E.
Note: This facility will be probably be adapted to the zLOG framework. Note: This facility will be probably be adapted to the zLOG framework.
""" """
def __init__(self, filename): def __init__(self, filename):
self.file=open(filename, 'a+b') self.file=open(filename, 'a+b')
l=thread.allocate_lock() l=thread.allocate_lock()
self._acquire=l.acquire self._acquire=l.acquire
self._release=l.release self._release=l.release
def log(self, code, request_id, data=''): def log(self, code, request_id, data=''):
self._acquire() self._acquire()
try: try:
t=time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time())) t=time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time()))
self.file.write( self.file.write(
'%s %s %s %s\n' % (code, request_id, t, data) '%s %s %s %s\n' % (code, request_id, t, data)
) )
finally: self.file.flush()
self._release() finally:
self._release()
def log(*args): pass def log(*args): pass
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment