diff options
Diffstat (limited to 'wsgitools')
-rw-r--r-- | wsgitools/filters.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/wsgitools/filters.py b/wsgitools/filters.py index 11623ef..8f4f6a5 100644 --- a/wsgitools/filters.py +++ b/wsgitools/filters.py @@ -220,19 +220,26 @@ __all__.append("RequestLogWSGIFilter") class RequestLogWSGIFilter(BaseWSGIFilter): """This filter logs all requests in the apache log file format.""" @classmethod - def creator(cls, log): + def creator(cls, log, flush=True): """Returns a function creating L{RequestLogWSGIFilter}s on given log file. log has to be a file-like object. @type log: file-like + @type flush: bool + @param flush: if True, invoke the flush method on log after each + write invocation """ - return lambda:cls(log) - def __init__(self, log=sys.stdout): + return lambda:cls(log, flush) + def __init__(self, log=sys.stdout, flush=True): """ @type log: file-like + @type flush: bool + @param flush: if True, invoke the flush method on log after each + write invocation """ BaseWSGIFilter.__init__(self) assert hasattr(log, "write") self.log = log + self.flush = flush self.remote = "?" self.user = "-" self.time = time.strftime("%d/%b/%Y:%T %z") @@ -291,6 +298,8 @@ class RequestLogWSGIFilter(BaseWSGIFilter): else: line += " -" self.log.write("%s\n" % line) + if self.flush: + self.log.flush() __all__.append("TimerWSGIFilter") class TimerWSGIFilter(BaseWSGIFilter): |