Update app.py
Browse files
app.py
CHANGED
@@ -175,17 +175,19 @@ async def logging_middleware(request, handler):
|
|
175 |
response = await handler(request)
|
176 |
end_time = datetime.datetime.now()
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
|
|
189 |
|
190 |
return response
|
191 |
except Exception as e:
|
|
|
175 |
response = await handler(request)
|
176 |
end_time = datetime.datetime.now()
|
177 |
|
178 |
+
# 只有当 URL 参数存在且不为 '-' 时才记录日志
|
179 |
+
if 'url' in request.query and request.query['url'] != '-':
|
180 |
+
timestamp = end_time.strftime('%Y-%m-%d %H:%M:%S')
|
181 |
+
client_ip = get_client_ip(request)
|
182 |
+
target_url = request.query.get('url')
|
183 |
+
no_cache = 'nocache' in request.query
|
184 |
+
status_code = response.status
|
185 |
+
proxy_count = response.headers.get('X-Proxy-Count', '0')
|
186 |
+
cache_hit = "Hit" if response.headers.get('X-Cache-Hit') == 'True' else "Miss"
|
187 |
+
cache_time = response.headers.get('X-Cache-Time', '-')
|
188 |
+
|
189 |
+
log_message = f"{timestamp} - {client_ip} - \"GET /?url={target_url}{'&nocache' if no_cache else ''}\" - Status: {status_code} - Proxies: {proxy_count} - Cache: {cache_hit} - CacheTime: {cache_time} - NoCache: {'Yes' if no_cache else 'No'}"
|
190 |
+
print(log_message, flush=True)
|
191 |
|
192 |
return response
|
193 |
except Exception as e:
|