logging: don't pick up later mutations

This commit is contained in:
Maximilian Hils 2021-06-19 14:35:39 +02:00
parent d6975e0b80
commit 2fe4a49d8f
2 changed files with 10 additions and 1 deletions

View File

@ -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):

View File

@ -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)"