mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Display errors on sys.stderr
This commit is contained in:
parent
c2e2fd1751
commit
2e9a34faa9
@ -27,9 +27,10 @@ def colorful(line, styles):
|
|||||||
|
|
||||||
|
|
||||||
class Dumper:
|
class Dumper:
|
||||||
def __init__(self, outfile=sys.stdout):
|
def __init__(self, outfile=sys.stdout, errfile=sys.stderr):
|
||||||
self.filter: flowfilter.TFilter = None
|
self.filter: flowfilter.TFilter = None
|
||||||
self.outfp: typing.io.TextIO = outfile
|
self.outfp: typing.io.TextIO = outfile
|
||||||
|
self.errfp: typing.io.TextIO = errfile
|
||||||
|
|
||||||
def load(self, loader):
|
def load(self, loader):
|
||||||
loader.add_option(
|
loader.add_option(
|
||||||
@ -70,6 +71,13 @@ class Dumper:
|
|||||||
if self.outfp:
|
if self.outfp:
|
||||||
self.outfp.flush()
|
self.outfp.flush()
|
||||||
|
|
||||||
|
def echo_error(self, text, ident=None, **style):
|
||||||
|
if ident:
|
||||||
|
text = indent(ident, text)
|
||||||
|
click.secho(text, file=self.errfp, **style)
|
||||||
|
if self.errfp:
|
||||||
|
self.errfp.flush()
|
||||||
|
|
||||||
def _echo_headers(self, headers):
|
def _echo_headers(self, headers):
|
||||||
for k, v in headers.fields:
|
for k, v in headers.fields:
|
||||||
k = strutils.bytes_to_escaped_str(k)
|
k = strutils.bytes_to_escaped_str(k)
|
||||||
@ -243,7 +251,7 @@ class Dumper:
|
|||||||
self.echo_flow(f)
|
self.echo_flow(f)
|
||||||
|
|
||||||
def websocket_error(self, f):
|
def websocket_error(self, f):
|
||||||
self.echo(
|
self.echo_error(
|
||||||
"Error in WebSocket connection to {}: {}".format(
|
"Error in WebSocket connection to {}: {}".format(
|
||||||
human.format_address(f.server_conn.address), f.error
|
human.format_address(f.server_conn.address), f.error
|
||||||
),
|
),
|
||||||
@ -268,7 +276,7 @@ class Dumper:
|
|||||||
f.close_reason))
|
f.close_reason))
|
||||||
|
|
||||||
def tcp_error(self, f):
|
def tcp_error(self, f):
|
||||||
self.echo(
|
self.echo_error(
|
||||||
"Error in TCP connection to {}: {}".format(
|
"Error in TCP connection to {}: {}".format(
|
||||||
human.format_address(f.server_conn.address), f.error
|
human.format_address(f.server_conn.address), f.error
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user