diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-10 10:47:28 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-10 10:47:28 +1200 |
commit | 2cf79b79126c0845067abce9ab24500810772404 (patch) | |
tree | e0a9c184a815285c4395f3b26e6062f821a2b338 /pathod/log.py | |
parent | c421c41307ce1ced06dae9f1d37fb516e6437f1e (diff) | |
download | mitmproxy-2cf79b79126c0845067abce9ab24500810772404.tar.gz mitmproxy-2cf79b79126c0845067abce9ab24500810772404.tar.bz2 mitmproxy-2cf79b79126c0845067abce9ab24500810772404.zip |
Remove timestamps from pathoc output
Pathoc is an interactive tool, no need for a long leading timestamp. More
generally, make timestamps optional in the logging mechanism so we can
configure this with command-line flags or something down the track.
Diffstat (limited to 'pathod/log.py')
-rw-r--r-- | pathod/log.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/pathod/log.py b/pathod/log.py index 5bf55de4..1d3ec356 100644 --- a/pathod/log.py +++ b/pathod/log.py @@ -1,17 +1,14 @@ -import datetime +import time import six -from netlib import strutils +from netlib import strutils, human -TIMEFMT = '%d-%m-%y %H:%M:%S' - -def write_raw(fp, lines): +def write_raw(fp, lines, timestamp=True): if fp: - fp.write( - "%s: " % datetime.datetime.now().strftime(TIMEFMT) - ) + if timestamp: + fp.write(human.format_timestamp(time.time())) for i in lines: fp.write(i) fp.write("\n") @@ -20,11 +17,12 @@ def write_raw(fp, lines): class LogCtx(object): - def __init__(self, fp, hex, rfile, wfile): + def __init__(self, fp, hex, timestamp, rfile, wfile): self.lines = [] self.fp = fp self.suppressed = False self.hex = hex + self.timestamp = timestamp self.rfile, self.wfile = rfile, wfile def __enter__(self): @@ -50,7 +48,8 @@ class LogCtx(object): self.fp, [ "\n".join(self.lines), - ] + ], + timestamp = self.timestamp ) if exc_value: six.reraise(exc_type, exc_value, traceback) @@ -71,13 +70,14 @@ class LogCtx(object): class ConnectionLogger: - def __init__(self, fp, hex, rfile, wfile): + def __init__(self, fp, hex, timestamp, rfile, wfile): self.fp = fp self.hex = hex self.rfile, self.wfile = rfile, wfile + self.timestamp = timestamp def ctx(self): - return LogCtx(self.fp, self.hex, self.rfile, self.wfile) + return LogCtx(self.fp, self.hex, self.timestamp, self.rfile, self.wfile) def write(self, lines): - write_raw(self.fp, lines) + write_raw(self.fp, lines, timestamp=self.timestamp) |