diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-05-31 18:03:41 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-05-31 18:03:41 +1200 |
commit | effd29b51a3b54c2d346919bd09933fc6f440397 (patch) | |
tree | 5a8de782bc3f2254bcafc8a69f3b564a5125b4d6 /libpathod/log.py | |
parent | af666612123073ae835dc8f52905e4268741a3b0 (diff) | |
download | mitmproxy-effd29b51a3b54c2d346919bd09933fc6f440397.tar.gz mitmproxy-effd29b51a3b54c2d346919bd09933fc6f440397.tar.bz2 mitmproxy-effd29b51a3b54c2d346919bd09933fc6f440397.zip |
Refactor logging, fix conversion to websocket handler
Diffstat (limited to 'libpathod/log.py')
-rw-r--r-- | libpathod/log.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/libpathod/log.py b/libpathod/log.py index 568d4d66..c60a151c 100644 --- a/libpathod/log.py +++ b/libpathod/log.py @@ -4,9 +4,20 @@ import netlib.utils import netlib.tcp import netlib.http +TIMEFMT = '%d-%m-%y %H:%M:%S' + + +def write(fp, lines): + if fp: + fp.write( + "%s: " % datetime.datetime.now().strftime(TIMEFMT) + ) + for i in lines: + fp.write(i) + fp.flush() + class Log: - TIMEFMT = '%d-%m-%y %H:%M:%S' def __init__(self, fp, hex, rfile, wfile): self.lines = [] @@ -42,12 +53,13 @@ class Log: self("Disconnected") elif exc_type == netlib.http.HttpError: self("HTTP Error: %s" % exc_value.message) - self.fp.write( - "%s: "%datetime.datetime.now().strftime(self.TIMEFMT) + write( + self.fp, + [ + "\n".join(self.lines), + "\n" + ] ) - self.fp.write("\n".join(self.lines)) - self.fp.write("\n") - self.fp.flush() def suppress(self): self.suppressed = True |