From 660ca90232886ab05aa5db3b9fdaa8e1a5e087ee Mon Sep 17 00:00:00 2001 From: Sam Mirazi Date: Tue, 3 Jun 2025 12:13:54 -0700 Subject: [PATCH] Refactor: Enhance Flask Application Logging for Clarity and Conciseness This commit refines the logging output of the Flask application (`app_flask/Flask_with_delay.py`) to improve readability and provide clearer status indicators during benchmark runs. Two key changes were implemented: 1. **Disable Werkzeug's Default Access Logs:** The standard Werkzeug request logger (which produces lines like `127.0.0.1 - - [timestamp] "GET / HTTP/1.1" 200 -`) has been disabled. This is achieved by getting the 'werkzeug' logger instance and setting its logging level to `ERROR`. This change significantly reduces log verbosity, allowing the custom application logs to be more prominent and easier to follow. 2. **Add Explicit "OK" Confirmation to Custom Logs:** The custom log message printed by the Flask server upon successful request processing has been augmented with an " - OK" suffix. The log line now appears as `[Flask Server] Request {id} processed in {time}s - OK`. This provides an unambiguous visual confirmation that each request was handled successfully by the server, which is particularly useful when monitoring benchmark progress. These modifications aim to make the Flask server's console output more focused and informative, aiding in the analysis of benchmark results by removing redundant log entries and clearly indicating successful operations. --- app_flask/Flask_with_delay.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app_flask/Flask_with_delay.py b/app_flask/Flask_with_delay.py index 904643e..b3afc75 100644 --- a/app_flask/Flask_with_delay.py +++ b/app_flask/Flask_with_delay.py @@ -2,9 +2,14 @@ from flask import Flask, Response import time import webbrowser from datetime import datetime # Added for timestamping +import logging # Added import app = Flask(__name__) +# Disable Werkzeug's default logger +log = logging.getLogger('werkzeug') +log.setLevel(logging.ERROR) + request_counter = 0 # Global counter @app.route("/") @@ -14,13 +19,13 @@ def home(): request_counter = request_id start_time = datetime.now() - print(f"[Flask Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}") + # print(f"[Flask Server] Request {request_id} received at {start_time.strftime('%Y-%m-%d %H:%M:%S.%f')}") # Removed this line time.sleep(0.3) # simulate slow work end_time = datetime.now() processing_time = (end_time - start_time).total_seconds() - print(f"[Flask Server] Request {request_id} finishing at {end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}, processed in {processing_time:.2f}s") + print(f"[Flask Server] Request {request_id} processed in {processing_time:.2f}s - OK") # Kept and simplified this line, and added - OK html = f"

Flask Server: Request {request_id} processed in {processing_time:.2f}s

" # Updated content return Response(html, mimetype="text/html") -- 2.25.1