3232 Notice ,
3333 Gtfsdataset ,
3434)
35- from shared .helpers .logger import Logger
35+ from shared .helpers .logger import init_logger
3636from shared .helpers .transform import get_nested_value
3737from shared .helpers .feed_status import update_feed_statuses_query
3838
39- logging . basicConfig ( level = logging . INFO )
39+ init_logger ( )
4040
4141FILES_ENDPOINT = os .getenv ("FILES_ENDPOINT" )
4242
@@ -91,11 +91,11 @@ def validate_json_report(json_report_url):
9191 try :
9292 json_report , code = read_json_report (json_report_url )
9393 if code != 200 :
94- logging .error (f "Error reading JSON report: { code } " )
94+ logging .error ("Error reading JSON report: %s" , code )
9595 return f"Error reading JSON report at url { json_report_url } ." , code
9696 return json_report , 200
9797 except Exception as error : # JSONDecodeError or RequestException
98- logging .error (f "Error reading JSON report: { error } " )
98+ logging .error ("Error reading JSON report: %s" , str ( error ) )
9999 return f"Error reading JSON report at url { json_report_url } : { error } " , 500
100100
101101
@@ -112,11 +112,13 @@ def parse_json_report(json_report):
112112 if "validatorVersion" in json_report ["summary" ]:
113113 version = json_report ["summary" ]["validatorVersion" ]
114114 logging .info (
115- f"Validation report validated at { validated_at } with version { version } ."
115+ "Validation report validated_at: %s with version: %s." ,
116+ validated_at ,
117+ version ,
116118 )
117119 return validated_at , version
118120 except Exception as error :
119- logging .error (f "Error parsing JSON report: { error } " )
121+ logging .error ("Error parsing JSON report: %s" , error )
120122 raise Exception (f"Error parsing JSON report: { error } " )
121123
122124
@@ -135,7 +137,7 @@ def generate_report_entities(
135137 """
136138 entities = []
137139 report_id = f"{ dataset_stable_id } _{ version } "
138- logging .info (f "Creating validation report entities for { report_id } ." )
140+ logging .info ("Creating validation report entities for: %s." , report_id )
139141
140142 html_report_url = (
141143 f"{ FILES_ENDPOINT } /{ feed_stable_id } /{ dataset_stable_id } /report_{ version } .html"
@@ -146,7 +148,7 @@ def generate_report_entities(
146148 # Check if report already exists
147149 # If exists, the function should graceful finish avoiding retry mechanism to trigger again
148150 if get_validation_report (report_id , session ):
149- logging .warning (f "Validation report { report_id } already exists. Terminating." )
151+ logging .warning ("Validation report %s already exists. Terminating." , report_id )
150152 return []
151153
152154 validation_report_entity = Validationreport (
@@ -284,8 +286,9 @@ def create_validation_report_entities(
284286 return str (error ), 200
285287
286288 update_feed_statuses_query (db_session , [feed_stable_id ])
287-
288- return f"Created { len (entities )} entities." , 200
289+ result = f"Created { len (entities )} entities."
290+ logging .info (result )
291+ return result , 200
289292 except Exception as error :
290293 logging .error ("Error creating validation report entities: : %s" , error )
291294 return f"Error creating validation report entities: { error } " , 500
@@ -314,10 +317,9 @@ def process_validation_report(request):
314317 :param request: Request object containing 'dataset_id' and 'feed_id'
315318 :return: HTTP response indicating the result of the operation
316319 """
317- Logger .init_logger ()
318320 request_json = request .get_json (silent = True )
319321 logging .info (
320- f "Processing validation report function called with request: { request_json } "
322+ "Processing validation report function called with request: %s" , request_json
321323 )
322324 if (
323325 not request_json
@@ -335,7 +337,10 @@ def process_validation_report(request):
335337 feed_id = request_json ["feed_id" ]
336338 validator_version = request_json ["validator_version" ]
337339 logging .info (
338- f"Processing validation report version { validator_version } for dataset { dataset_id } in feed { feed_id } ."
340+ "Processing validation report version: %s for dataset: %s in feed: %s." ,
341+ validator_version ,
342+ dataset_id ,
343+ feed_id ,
339344 )
340345 return create_validation_report_entities (feed_id , dataset_id , validator_version )
341346
@@ -370,8 +375,10 @@ def compute_validation_report_counters(request, db_session: Session):
370375 .offset (offset )
371376 .all ()
372377 )
373- print (
374- f"Processing { len (validation_reports )} validation reports from offset { offset } ."
378+ logging .info (
379+ "Processing %s validation reports from offset: %s." ,
380+ len (validation_reports ),
381+ offset ,
375382 )
376383 # Break the loop if no more reports are found
377384 if len (validation_reports ) == 0 :
@@ -380,10 +387,17 @@ def compute_validation_report_counters(request, db_session: Session):
380387 for report in validation_reports :
381388 populate_counters (report .notices , report )
382389 logging .info (
383- f"Updated ValidationReport { report .id } with counters: "
384- f"INFO={ report .total_info } , WARNING={ report .total_warning } , ERROR={ report .total_error } , "
385- f"Unique INFO Code={ report .unique_info_count } , Unique WARNING Code={ report .unique_warning_count } , "
386- f"Unique ERROR Code={ report .unique_error_count } "
390+ "Updated ValidationReport %s with counters: "
391+ "INFO=%s, WARNING=%s, ERROR=%s, "
392+ "Unique INFO Code=%s, Unique WARNING Code=%s, "
393+ "Unique ERROR Code=%s" ,
394+ report .id ,
395+ report .total_info ,
396+ report .total_warning ,
397+ report .total_error ,
398+ report .unique_info_count ,
399+ report .unique_warning_count ,
400+ report .unique_error_count ,
387401 )
388402
389403 # Commit the changes for the current batch
@@ -420,7 +434,7 @@ def process_validation_report_notices(notices):
420434 total_error += notice .total_notices
421435 error_codes .add (notice .notice_code )
422436 case _:
423- logging .warning (f "Unknown severity: { notice .severity } " )
437+ logging .warning ("Unknown severity: %s" , notice .severity )
424438
425439 return {
426440 "total_info" : total_info ,
0 commit comments