aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/builtins/wsgiapp.py2
-rw-r--r--mitmproxy/controller.py41
-rw-r--r--mitmproxy/log.py40
-rw-r--r--mitmproxy/master.py5
-rw-r--r--mitmproxy/proxy/root_context.py4
-rw-r--r--mitmproxy/proxy/server.py4
-rw-r--r--test/mitmproxy/builtins/test_termlog.py6
7 files changed, 51 insertions, 51 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))
diff --git a/test/mitmproxy/builtins/test_termlog.py b/test/mitmproxy/builtins/test_termlog.py
index 1564b53f..49a8be83 100644
--- a/test/mitmproxy/builtins/test_termlog.py
+++ b/test/mitmproxy/builtins/test_termlog.py
@@ -2,7 +2,7 @@ from .. import mastertest
import io
from mitmproxy.builtins import termlog
-from mitmproxy import controller
+from mitmproxy import log
from mitmproxy import dump
@@ -11,7 +11,7 @@ class TestTermLog(mastertest.MasterTest):
t = termlog.TermLog()
sio = io.StringIO()
t.configure(dump.Options(tfile = sio, verbosity = 2), set([]))
- t.log(controller.LogEntry("one", "info"))
+ t.log(log.LogEntry("one", "info"))
assert "one" in sio.getvalue()
- t.log(controller.LogEntry("two", "debug"))
+ t.log(log.LogEntry("two", "debug"))
assert "two" not in sio.getvalue()