MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / MitmFormatter

Class MitmFormatter

mitmproxy/log.py:36–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class MitmFormatter(logging.Formatter):
37 def __init__(self, colorize: bool):
38 super().__init__()
39 self.colorize = colorize
40 time = "[%s]"
41 client = "[%s]"
42 if colorize:
43 time = miniclick.style(time, fg="cyan", dim=True)
44 client = miniclick.style(client, fg="yellow", dim=True)
45
46 self.with_client = f"{time}{client} %s"
47 self.without_client = f"{time} %s"
48
49 default_time_format = "%H:%M:%S"
50 default_msec_format = "%s.%03d"
51
52 def format(self, record: logging.LogRecord) -> str:
53 time = self.formatTime(record)
54 message = record.getMessage()
55 if record.exc_info:
56 message = f"{message}\n{self.formatException(record.exc_info)}"
57 if self.colorize:
58 message = miniclick.style(
59 message,
60 fg=LOG_COLORS.get(record.levelno),
61 # dim=(record.levelno <= logging.DEBUG)
62 )
63 if client := getattr(record, "client", None):
64 client = human.format_address(client)
65 return self.with_client % (time, client, message)
66 else:
67 return self.without_client % (time, message)
68
69
70class MitmLogHandler(logging.Handler):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…