Skip to content

Commit 102e78b

Browse files
authored
🔊 Improve handler logs (#178)
1 parent 9e98ac8 commit 102e78b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

‎electrumx/server/http_middleware.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ def success_resp(data) -> web.Response:
9797

9898
def request_middleware(self) -> web_middlewares:
9999
async def factory(app: web.Application, handler):
100-
async def middleware_handler(request):
101-
self.logger.info('Request {} comming'.format(request))
100+
async def middleware_handler(request: web.Request):
101+
# Log request details as a future.
102+
async def log_request():
103+
method = request.path
104+
params = await request.json() if request.content_length else None
105+
self.logger.debug(f'HTTP request handling: [method] {method}, [params]: {params}')
106+
asyncio.ensure_future(log_request())
107+
102108
if not self.env.enable_rate_limit:
103109
response = await handler(request)
104110
if isinstance(response, web.Response):

‎electrumx/server/session.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,14 +1193,18 @@ def sub_count(self):
11931193
return 0
11941194

11951195
async def handle_request(self, request):
1196-
'''Handle an incoming request. ElectrumX doesn't receive
1196+
"""Handle an incoming request. ElectrumX doesn't receive
11971197
notifications from client sessions.
1198-
'''
1198+
"""
11991199
if isinstance(request, Request):
12001200
handler = self.request_handlers.get(request.method)
1201+
method = request.method
1202+
args = request.args
12011203
else:
12021204
handler = None
1203-
method = 'invalid method' if handler is None else request.method
1205+
method = 'invalid method'
1206+
args = None
1207+
self.logger.debug(f'Session request handling: [method] {method}, [args] {args}')
12041208

12051209
# If DROP_CLIENT_UNKNOWN is enabled, check if the client identified
12061210
# by calling server.version previously. If not, disconnect the session

0 commit comments

Comments
 (0)