diff --git a/mitmproxy/log.py b/mitmproxy/log.py index 9d4af8b79..0713df964 100644 --- a/mitmproxy/log.py +++ b/mitmproxy/log.py @@ -6,7 +6,9 @@ from mitmproxy import hooks class LogEntry: def __init__(self, msg, level): - self.msg = msg + # it's important that we serialize to string here already so that we don't pick up changes + # happening after this log statement. + self.msg = str(msg) self.level = level def __eq__(self, other): diff --git a/test/mitmproxy/test_log.py b/test/mitmproxy/test_log.py index 349e3ac86..225087e80 100644 --- a/test/mitmproxy/test_log.py +++ b/test/mitmproxy/test_log.py @@ -9,3 +9,10 @@ def test_logentry(): assert e == e assert e != f assert e != 42 + + +def test_dont_pick_up_mutations(): + x = {"foo": "bar"} + e = log.LogEntry(x, "info") + x["foo"] = "baz" # this should not affect the log entry anymore. + assert repr(e) == "LogEntry({'foo': 'bar'}, info)"