Skip to content

Commit 0f26c09

Browse files
authored
Merge pull request #153 from mobidata-bw/fix-request-logging
fix request logging
2 parents 8b74507 + d95d320 commit 0f26c09

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ CMD [\
3030
# > Log verbosity.
3131
# > Default: info
3232
# > Choices: error, warn, info, alert, debug
33+
# > Flow Detail
34+
# > Default: 1
35+
# > Choices: 0, 1, 2, 3, 4
36+
# > Set to 0, because request logging is done by addons.py
3337
# https://docs.mitmproxy.org/stable/concepts-options/#available-options
34-
"mitmdump -s addons.py --set termlog_verbosity=$LOG_LEVEL" \
38+
"mitmdump -s addons.py --set termlog_verbosity=$LOG_LEVEL --set flow_detail=0" \
3539
]
3640

3741
# When sending an HTTP request with `Host: localhost`, mitmproxy will respond with 502.

app/app.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import json
8+
import logging
89
from importlib import import_module
910
from inspect import isclass
1011
from json import JSONDecodeError
@@ -17,6 +18,8 @@
1718
from app.base_converter import BaseConverter
1819
from app.config_helper import ConfigHelper
1920

21+
logger = logging.getLogger('converters.requests')
22+
2023

2124
class App:
2225
json_converters: Dict[str, List[BaseConverter]]
@@ -50,6 +53,9 @@ def request(self, flow: HTTPFlow):
5053
flow.request.port = 443
5154

5255
def response(self, flow: HTTPFlow):
56+
# Log requests
57+
logger.info(f'{flow.request.method} {flow.request.url}: HTTP {"-" if flow.response is None else flow.response.status_code}')
58+
5359
# if there is no converter for the requested host, don't do anything
5460
if flow.request.host not in self.json_converters:
5561
return

0 commit comments

Comments
 (0)