From 218e127e749cf533a6410c2905b22cc88321c935 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 27 Apr 2017 19:08:01 +1200 Subject: 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. --- mitmproxy/addons/save.py | 2 ++ mitmproxy/log.py | 11 ++++++++++- mitmproxy/tools/console/master.py | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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: -- cgit v1.2.3