diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2018-04-04 14:46:29 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-07 09:02:10 +1200 |
commit | 6a08ef465f3af6cb2044baf98279de1071538f5a (patch) | |
tree | 183c5821a7a5d4debd8bd779c5596c280c48cabc /mitmproxy/addonmanager.py | |
parent | ea213782d8adaa21aa99f2de818172ee872cf3e9 (diff) | |
download | mitmproxy-6a08ef465f3af6cb2044baf98279de1071538f5a.tar.gz mitmproxy-6a08ef465f3af6cb2044baf98279de1071538f5a.tar.bz2 mitmproxy-6a08ef465f3af6cb2044baf98279de1071538f5a.zip |
asyncio: remove master.add_log, in favor of a persistent log.Log instance
Diffstat (limited to 'mitmproxy/addonmanager.py')
-rw-r--r-- | mitmproxy/addonmanager.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index 418ab046..7c446c80 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -41,8 +41,8 @@ class StreamLog: """ A class for redirecting output using contextlib. """ - def __init__(self, log): - self.log = log + def __init__(self, lg): + self.log = lg def write(self, buf): if buf.strip(): @@ -55,13 +55,7 @@ class StreamLog: @contextlib.contextmanager def safecall(): - # resolve ctx.master here. - # we want to be threadsafe, and ctx.master may already be cleared when an addon prints(). - channel = ctx.master.channel - # don't use master.add_log (which is not thread-safe). Instead, put on event queue. - stdout_replacement = StreamLog( - lambda message: channel("log", log.LogEntry(message, "warn")) - ) + stdout_replacement = StreamLog(lambda message: ctx.log.warn(message)) try: with contextlib.redirect_stdout(stdout_replacement): yield |