diff options
author | Helmut Grohne <helmut@subdivi.de> | 2010-06-04 21:55:56 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2010-06-04 21:55:56 +0200 |
commit | 55492002da9f49e4eb4ee94ab73e232546f0c45f (patch) | |
tree | 5d58bca916b25c80f65fd5687da74287675f6124 /wsgitools | |
parent | a4ed31012e689394ce309f01948a68ca101199be (diff) | |
download | wsgitools-55492002da9f49e4eb4ee94ab73e232546f0c45f.tar.gz |
flush log file in RequestLogWSGIFilter by default
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): |