From 55492002da9f49e4eb4ee94ab73e232546f0c45f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 4 Jun 2010 21:55:56 +0200 Subject: flush log file in RequestLogWSGIFilter by default --- wsgitools/filters.py | 15 ++++++++++++--- 1 file 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): -- cgit v1.2.3