File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 18
18
@app .before_request
19
19
def start_timer ():
20
20
g .start = time .time ()
21
- print (f"[{ time .strftime ('%H:%M:%S' )} ] --> { request .method } { request .path } started" )
21
+
22
+ if request .path == "/graphql" and request .method == "POST" :
23
+ try :
24
+ # Try to extract the GraphQL query name for better logging
25
+ query_data = request .get_json ()
26
+ if query_data and 'query' in query_data :
27
+ g .query = query_data ['query' ].split ("{" , 1 )[0 ].strip ()
28
+ logging .info (f"[{ time .strftime ('%H:%M:%S' )} ] --> GraphQL { g .query } started" )
29
+ except :
30
+ pass
31
+
32
+ logging .info (f"[{ time .strftime ('%H:%M:%S' )} ] --> { request .method } { request .path } started" )
22
33
23
34
@app .after_request
24
35
def log_response_time (response ):
25
36
if hasattr (g , 'start' ):
26
37
duration = time .time () - g .start
27
- print (f"[{ time .strftime ('%H:%M:%S' )} ] <-- { request .method } { request .path } finished in { duration :.2f} s" )
38
+
39
+ if duration > 5.0 : # Flag slow requests
40
+ if hasattr (g , 'query' ):
41
+ logging .warning (f"[{ time .strftime ('%H:%M:%S' )} ] <-- SLOW GraphQL { g .query } ({ duration :.2f} s)" )
42
+ else :
43
+ logging .warning (f"[{ time .strftime ('%H:%M:%S' )} ] <-- SLOW { request .method } { request .path } ({ duration :.2f} s)" )
44
+ else :
45
+ if hasattr (g , 'query' ):
46
+ logging .info (f"[{ time .strftime ('%H:%M:%S' )} ] <-- GraphQL { g .query } finished in { duration :.2f} s" )
47
+ else :
48
+ logging .info (f"[{ time .strftime ('%H:%M:%S' )} ] <-- { request .method } { request .path } finished in { duration :.2f} s" )
28
49
return response
50
+
29
51
30
52
# Configure logging
31
53
logging .basicConfig (
Original file line number Diff line number Diff line change @@ -223,6 +223,11 @@ def process_game_data(game_data):
223
223
game_data ["sport" ],
224
224
state
225
225
)
226
+ if isinstance (curr_game , list ):
227
+ if curr_game :
228
+ curr_game = curr_game [0 ]
229
+ else :
230
+ curr_game = None
226
231
if curr_game :
227
232
updates = {
228
233
"time" : game_time ,
You can’t perform that action at this time.
0 commit comments