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 | |
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')
-rw-r--r-- | pathod/log.py | 26 | ||||
-rw-r--r-- | pathod/pathoc.py | 8 | ||||
-rw-r--r-- | pathod/pathod.py | 2 |
3 files changed, 20 insertions, 16 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) diff --git a/pathod/pathoc.py b/pathod/pathoc.py index 3eb91637..88405698 100644 --- a/pathod/pathoc.py +++ b/pathod/pathoc.py @@ -18,7 +18,7 @@ from netlib.exceptions import HttpException, TcpDisconnect, TcpTimeout, TlsExcep NetlibException from netlib.http import http1, http2 -from . import log, language +from pathod import log, language import logging from netlib.tutils import treq @@ -100,6 +100,7 @@ class WebsocketFrameReader(threading.Thread): self.logger = log.ConnectionLogger( self.logfp, self.hexdump, + False, rfile if showresp else None, None ) @@ -216,7 +217,8 @@ class Pathoc(tcp.TCPClient): self.fp, "HTTP/2 requires ALPN support. " "Please use OpenSSL >= 1.0.2. " - "Pathoc might not be working as expected without ALPN." + "Pathoc might not be working as expected without ALPN.", + timestamp = False ) self.protocol = http2.HTTP2Protocol(self, dump_frames=self.http2_framedump) else: @@ -372,6 +374,7 @@ class Pathoc(tcp.TCPClient): logger = log.ConnectionLogger( self.fp, self.hexdump, + False, None, self.wfile if self.showreq else None, ) @@ -412,6 +415,7 @@ class Pathoc(tcp.TCPClient): logger = log.ConnectionLogger( self.fp, self.hexdump, + False, self.rfile if self.showresp else None, self.wfile if self.showreq else None, ) diff --git a/pathod/pathod.py b/pathod/pathod.py index ed35a92e..d1cc9980 100644 --- a/pathod/pathod.py +++ b/pathod/pathod.py @@ -266,7 +266,7 @@ class PathodHandler(tcp.BaseHandler): lr = self.rfile if self.server.logreq else None lw = self.wfile if self.server.logresp else None - logger = log.ConnectionLogger(self.logfp, self.server.hexdump, lr, lw) + logger = log.ConnectionLogger(self.logfp, self.server.hexdump, True, lr, lw) self.settings.protocol = self.protocol |