Screen output elimination

0 views
Skip to first unread message

Attish

unread,
Nov 8, 2009, 4:57:47 AM11/8/09
to web.py
I have also hit this problem, and I found a simple solution: create a
dummy
"file" class with only one method, a 'write()' that swallows all
output, or,
better optionally collects lines of output in a list for later
processing. Like
this:

class Logger():
def __init__(self, log=None):
self._log = log

def write(self, data):
if self._log is None:
return
self._log.append(data)

Then:

sys.stderr = Logger(log)
WebApp = web.application(urls, globals())
WebApp.run()

You can even have Logger.write() discriminate according to the error
code (e.g. don't log 200 OK, log all other messages).
Reply all
Reply to author
Forward
0 new messages