diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 14:14:59 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 14:14:59 +1300 |
commit | 966418725b204491d2c40358c08bf56564307412 (patch) | |
tree | 3dfee4aae5dadcc11a200c0300715d65714e0a3e /mitmproxy | |
parent | 83dbefb224c0b0d77b226f80e37b5b3d6bebb703 (diff) | |
download | mitmproxy-966418725b204491d2c40358c08bf56564307412.tar.gz mitmproxy-966418725b204491d2c40358c08bf56564307412.tar.bz2 mitmproxy-966418725b204491d2c40358c08bf56564307412.zip |
controller.Log -> log.Log
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/builtins/wsgiapp.py | 2 | ||||
-rw-r--r-- | mitmproxy/controller.py | 41 | ||||
-rw-r--r-- | mitmproxy/log.py | 40 | ||||
-rw-r--r-- | mitmproxy/master.py | 5 | ||||
-rw-r--r-- | mitmproxy/proxy/root_context.py | 4 | ||||
-rw-r--r-- | mitmproxy/proxy/server.py | 4 |
6 files changed, 48 insertions, 48 deletions
diff --git a/mitmproxy/builtins/wsgiapp.py b/mitmproxy/builtins/wsgiapp.py index 9444fcec..d83a1e2e 100644 --- a/mitmproxy/builtins/wsgiapp.py +++ b/mitmproxy/builtins/wsgiapp.py @@ -29,7 +29,7 @@ class WSGIApp: **{"mitmproxy.master": ctx.master} ) if err: - ctx.log.warn("Error in wsgi app. %s" % err, "error") + ctx.log.error("Error in wsgi app. %s" % err) flow.reply.kill() raise exceptions.AddonHalt() diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 27fb4a0c..c5e125ce 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -3,47 +3,6 @@ import queue from mitmproxy import exceptions -class LogEntry: - def __init__(self, msg, level): - self.msg = msg - self.level = level - - -class Log: - """ - The central logger, exposed to scripts as mitmproxy.ctx.log. - """ - def __init__(self, master): - self.master = master - - def debug(self, txt): - """ - Log with level debug. - """ - self(txt, "debug") - - def info(self, txt): - """ - Log with level info. - """ - self(txt, "info") - - def warn(self, txt): - """ - Log with level warn. - """ - self(txt, "warn") - - def error(self, txt): - """ - Log with level error. - """ - self(txt, "error") - - def __call__(self, text, level="info"): - self.master.add_log(text, level) - - class Channel: """ The only way for the proxy server to communicate with the master diff --git a/mitmproxy/log.py b/mitmproxy/log.py new file mode 100644 index 00000000..8c28a9b1 --- /dev/null +++ b/mitmproxy/log.py @@ -0,0 +1,40 @@ + +class LogEntry: + def __init__(self, msg, level): + self.msg = msg + self.level = level + + +class Log: + """ + The central logger, exposed to scripts as mitmproxy.ctx.log. + """ + def __init__(self, master): + self.master = master + + def debug(self, txt): + """ + Log with level debug. + """ + self(txt, "debug") + + def info(self, txt): + """ + Log with level info. + """ + self(txt, "info") + + def warn(self, txt): + """ + Log with level warn. + """ + self(txt, "warn") + + def error(self, txt): + """ + Log with level error. + """ + self(txt, "error") + + def __call__(self, text, level="info"): + self.master.add_log(text, level) diff --git a/mitmproxy/master.py b/mitmproxy/master.py index b6286b89..ce1dd2c6 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -10,6 +10,7 @@ from mitmproxy import controller from mitmproxy import events from mitmproxy import exceptions from mitmproxy import models +from mitmproxy import log from mitmproxy.flow import io from mitmproxy.protocol import http_replay from netlib import basethread @@ -50,7 +51,7 @@ class Master: yield return mitmproxy_ctx.master = self - mitmproxy_ctx.log = controller.Log(self) + mitmproxy_ctx.log = log.Log(self) try: yield finally: @@ -66,7 +67,7 @@ class Master: level: debug, info, warn, error """ with self.handlecontext(): - self.addons("log", controller.LogEntry(e, level)) + self.addons("log", log.LogEntry(e, level)) def start(self): self.should_exit.clear() diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py index ef6aaf36..8064f12d 100644 --- a/mitmproxy/proxy/root_context.py +++ b/mitmproxy/proxy/root_context.py @@ -1,5 +1,5 @@ import netlib.exceptions -from mitmproxy import controller +from mitmproxy import log from mitmproxy import exceptions from mitmproxy import protocol from mitmproxy.proxy import modes @@ -113,7 +113,7 @@ class RootContext: for i in subs: full_msg.append(" -> " + i) full_msg = "\n".join(full_msg) - self.channel.tell("log", controller.LogEntry(full_msg, level)) + self.channel.tell("log", log.LogEntry(full_msg, level)) @property def layers(self): diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index 3d66812f..c2a6a5c3 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -5,7 +5,7 @@ import traceback import netlib.exceptions from mitmproxy import exceptions from mitmproxy import models -from mitmproxy import controller +from mitmproxy import log from mitmproxy.proxy import modes from mitmproxy.proxy import root_context from netlib import tcp @@ -151,4 +151,4 @@ class ConnectionHandler: def log(self, msg, level): msg = "{}: {}".format(repr(self.client_conn.address), msg) - self.channel.tell("log", controller.LogEntry(msg, level)) + self.channel.tell("log", log.LogEntry(msg, level)) |