11# pylint: disable=protected-access,too-many-instance-attributes,too-many-arguments,line-too-long
22"""Generic Pipeline object to define how DVE should be interacted with."""
33import json
4+ import logging
45import re
56from collections import defaultdict
67from collections .abc import Generator , Iterable , Iterator
@@ -57,6 +58,7 @@ def __init__(
5758 submitted_files_path : Optional [URI ],
5859 reference_data_loader : Optional [type [BaseRefDataLoader ]] = None ,
5960 job_run_id : Optional [int ] = None ,
61+ logger : Optional [logging .Logger ] = None ,
6062 ):
6163 self ._submitted_files_path = submitted_files_path
6264 self ._processed_files_path = processed_files_path
@@ -66,11 +68,16 @@ def __init__(
6668 self ._audit_tables = audit_tables
6769 self ._data_contract = data_contract
6870 self ._step_implementations = step_implementations
69- self ._logger = get_logger (__name__ )
71+ self ._logger = logger or get_logger (__name__ )
7072 self ._summary_lock = Lock ()
7173 self ._rec_tracking_lock = Lock ()
7274 self ._aggregates_lock = Lock ()
7375
76+ if self ._data_contract :
77+ self ._data_contract .logger = self ._logger
78+ if self ._step_implementations :
79+ self ._step_implementations .logger = self ._logger
80+
7481 @property
7582 def job_run_id (self ) -> Optional [int ]:
7683 """Unique Identifier for the job/process that is running this Pipeline."""
@@ -244,8 +251,7 @@ def audit_received_file_step(
244251 )
245252 continue
246253 except Exception as exc : # pylint: disable=W0703
247- self ._logger .error (f"audit_received_file raised exception: { exc } " )
248- self ._logger .exception (exc )
254+ self ._logger .exception ("audit_received_file raised exception:" )
249255 dump_processing_errors (
250256 fh .joinuri (self .processed_files_path , submission_id ),
251257 "audit_received" ,
@@ -301,8 +307,7 @@ def file_transformation(
301307 )
302308
303309 except MessageBearingError as exc :
304- self ._logger .error (f"Unexpected file transformation error: { exc } " )
305- self ._logger .exception (exc )
310+ self ._logger .exception ("Unexpected file transformation error:" )
306311 errors .extend (exc .messages )
307312
308313 if errors :
@@ -352,8 +357,7 @@ def file_transformation_step(
352357 )
353358 continue
354359 except Exception as exc : # pylint: disable=W0703
355- self ._logger .error (f"File transformation raised exception: { exc } " )
356- self ._logger .exception (exc )
360+ self ._logger .exception ("File transformation raised exception:" )
357361 dump_processing_errors (
358362 fh .joinuri (self .processed_files_path , sub_info .submission_id ),
359363 "file_transformation" ,
@@ -478,8 +482,7 @@ def data_contract_step(
478482 )
479483 continue
480484 except Exception as exc : # pylint: disable=W0703
481- self ._logger .error (f"Data Contract raised exception: { exc } " )
482- self ._logger .exception (exc )
485+ self ._logger .exception ("Data Contract raised exception:" )
483486 dump_processing_errors (
484487 fh .joinuri (self .processed_files_path , sub_info .submission_id ),
485488 "contract" ,
@@ -644,8 +647,7 @@ def business_rule_step(
644647 )
645648 continue
646649 except Exception as exc : # pylint: disable=W0703
647- self ._logger .error (f"Business Rules raised exception: { exc } " )
648- self ._logger .exception (exc )
650+ self ._logger .exception ("Business Rules raised exception:" )
649651 dump_processing_errors (
650652 fh .joinuri (self .processed_files_path , sub_info .submission_id ),
651653 "business_rules" ,
@@ -704,9 +706,8 @@ def _get_error_dataframes(self, submission_id: str):
704706 errors = None
705707 try :
706708 errors = json .load (f )
707- except UnicodeDecodeError as exc :
708- self ._logger .error (f"Error reading file: { file } " )
709- self ._logger .exception (exc )
709+ except UnicodeDecodeError :
710+ self ._logger .exception (f"Error reading file: { file } " )
710711 continue
711712 if not errors :
712713 continue
@@ -845,8 +846,7 @@ def error_report_step(
845846 )
846847 continue
847848 except Exception as exc : # pylint: disable=W0703
848- self ._logger .error (f"Error reports raised exception: { exc } " )
849- self ._logger .exception (exc )
849+ self ._logger .exception ("Error reports raised exception:" )
850850 dump_processing_errors (
851851 fh .joinuri (self .processed_files_path , sub_info .submission_id ),
852852 "error_report" ,
0 commit comments