| 34 | |
| 35 | |
| 36 | class 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 | |
| 70 | class MitmLogHandler(logging.Handler): |
no outgoing calls
no test coverage detected
searching dependent graphs…