aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-04-27 19:08:01 +1200
committerAldo Cortesi <aldo@nullcube.com>2017-04-27 19:08:01 +1200
commit218e127e749cf533a6410c2905b22cc88321c935 (patch)
tree8f8b80724b80395969dd48ae621c30f6d707d312
parentfde1159ae306be2db9c40db1de9e2f24286de8b9 (diff)
downloadmitmproxy-218e127e749cf533a6410c2905b22cc88321c935.tar.gz
mitmproxy-218e127e749cf533a6410c2905b22cc88321c935.tar.bz2
mitmproxy-218e127e749cf533a6410c2905b22cc88321c935.zip
Add an "alert" log level.
This has the same urgency as "info", but also signals to interactive tools that the user's attention should be drawn to the output, even if they're not looking at the event log. In the console app, this means the message appears in the status bar with a timeout.
-rw-r--r--mitmproxy/addons/save.py2
-rw-r--r--mitmproxy/log.py11
-rw-r--r--mitmproxy/tools/console/master.py5
3 files changed, 17 insertions, 1 deletions
diff --git a/mitmproxy/addons/save.py b/mitmproxy/addons/save.py
index 37dc6021..92b7c5be 100644
--- a/mitmproxy/addons/save.py
+++ b/mitmproxy/addons/save.py
@@ -56,6 +56,8 @@ class Save:
stream = io.FlowWriter(f)
for i in flows:
stream.add(i)
+ f.close()
+ ctx.log.alert("Saved %s flows." % len(flows))
def load(self, l):
l.add_command("save.file", self.save)
diff --git a/mitmproxy/log.py b/mitmproxy/log.py
index c2456cf1..a2e7ea99 100644
--- a/mitmproxy/log.py
+++ b/mitmproxy/log.py
@@ -24,6 +24,15 @@ class Log:
"""
self(txt, "info")
+ def alert(self, txt):
+ """
+ Log with level alert. Alerts have the same urgency as info, but
+ signals to interctive tools that the user's attention should be
+ drawn to the output even if they're not currently looking at the
+ event log.
+ """
+ self(txt, "alert")
+
def warn(self, txt):
"""
Log with level warn.
@@ -41,4 +50,4 @@ class Log:
def log_tier(level):
- return dict(error=0, warn=1, info=2, debug=3).get(level)
+ return dict(error=0, warn=1, info=2, alert=2, debug=3).get(level)
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py
index 8727d175..8c5376bd 100644
--- a/mitmproxy/tools/console/master.py
+++ b/mitmproxy/tools/console/master.py
@@ -39,6 +39,11 @@ EVENTLOG_SIZE = 10000
class Logger:
def log(self, evt):
signals.add_log(evt.msg, evt.level)
+ if evt.level == "alert":
+ signals.status_message.send(
+ message=str(evt.msg),
+ expire=2
+ )
class UnsupportedLog: