aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2018-05-08 15:24:02 +0200
committerGitHub <noreply@github.com>2018-05-08 15:24:02 +0200
commit0c101a4bccfb8460a11691cc17467d47d1974b2f (patch)
treecac672a0bfa819eac359db5ec1621d1c4de06aaf /examples
parentad74c18f74256537fd22037e8aec0e9707773fa0 (diff)
parent7d9b626d2ed304de0f5aa6083c782dcd00ed51dc (diff)
downloadmitmproxy-0c101a4bccfb8460a11691cc17467d47d1974b2f.tar.gz
mitmproxy-0c101a4bccfb8460a11691cc17467d47d1974b2f.tar.bz2
mitmproxy-0c101a4bccfb8460a11691cc17467d47d1974b2f.zip
Merge pull request #3106 from cortesi/noprint
Ditch the addon stdout wrapper
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/nonblocking.py5
-rw-r--r--examples/complex/tcp_message.py3
-rw-r--r--examples/simple/filter_flows.py4
-rw-r--r--examples/simple/log_events.py5
4 files changed, 8 insertions, 9 deletions
diff --git a/examples/complex/nonblocking.py b/examples/complex/nonblocking.py
index 264a1fdb..72c9c0ab 100644
--- a/examples/complex/nonblocking.py
+++ b/examples/complex/nonblocking.py
@@ -1,11 +1,12 @@
import time
from mitmproxy.script import concurrent
+from mitmproxy import ctx
@concurrent # Remove this and see what happens
def request(flow):
# You don't want to use mitmproxy.ctx from a different thread
- print("handle request: %s%s" % (flow.request.host, flow.request.path))
+ ctx.log.info("handle request: %s%s" % (flow.request.host, flow.request.path))
time.sleep(5)
- print("start request: %s%s" % (flow.request.host, flow.request.path))
+ ctx.log.info("start request: %s%s" % (flow.request.host, flow.request.path))
diff --git a/examples/complex/tcp_message.py b/examples/complex/tcp_message.py
index d7c9c42e..634e2a9f 100644
--- a/examples/complex/tcp_message.py
+++ b/examples/complex/tcp_message.py
@@ -9,6 +9,7 @@ example cmdline invocation:
mitmdump -T --host --tcp ".*" -q -s examples/tcp_message.py
"""
from mitmproxy.utils import strutils
+from mitmproxy import ctx
def tcp_message(tcp_msg):
@@ -17,7 +18,7 @@ def tcp_message(tcp_msg):
is_modified = False if modified_msg == tcp_msg.message else True
tcp_msg.message = modified_msg
- print(
+ ctx.log.info(
"[tcp_message{}] from {} {} to {} {}:\r\n{}".format(
" (modified)" if is_modified else "",
"client" if tcp_msg.sender == tcp_msg.client_conn else "server",
diff --git a/examples/simple/filter_flows.py b/examples/simple/filter_flows.py
index d252089c..aba240de 100644
--- a/examples/simple/filter_flows.py
+++ b/examples/simple/filter_flows.py
@@ -19,8 +19,8 @@ class Filter:
def response(self, flow: http.HTTPFlow) -> None:
if flowfilter.match(self.filter, flow):
- print("Flow matches filter:")
- print(flow)
+ ctx.log.info("Flow matches filter:")
+ ctx.log.info(flow)
addons = [Filter()]
diff --git a/examples/simple/log_events.py b/examples/simple/log_events.py
index b9aa2c1f..4f70e340 100644
--- a/examples/simple/log_events.py
+++ b/examples/simple/log_events.py
@@ -1,10 +1,7 @@
-"""
-It is recommended to use `ctx.log` for logging within a script.
-print() statements are equivalent to ctx.log.warn().
-"""
from mitmproxy import ctx
def load(l):
ctx.log.info("This is some informative text.")
+ ctx.log.warn("This is a warning.")
ctx.log.error("This is an error.")