diff --git a/haf/common/database.py b/haf/common/database.py index 5f89317..18a18eb 100644 --- a/haf/common/database.py +++ b/haf/common/database.py @@ -84,24 +84,24 @@ def connect_execute(self, sqlconfig:SQLConfig, sqlscript:list, **kwargs): for ss in sqlscript: if ss != None and ss != "None" and len(ss) > 5: if not run_background: - logger.info(f"{key} start {sqlconfig.host} execute {ss}") + logger.info(f"{key} start {sqlconfig.host} execute {ss}", __name__) cursor_m.execute(ss) data.append(cursor_m.fetchall()) if not run_background: - logger.info(f"{key} result {str(data)}") + logger.info(f"{key} result {str(data)}", __name__) elif isinstance(sqlscript, str): if sqlscript != None and sqlscript != "None" and "None" not in sqlscript and len(sqlscript) > 5: if not run_background: - logger.info(f"{key} start {sqlconfig.host} execute {sqlscript}") + logger.info(f"{key} start {sqlconfig.host} execute {sqlscript}", __name__) cursor_m.execute(sqlscript) data.append(cursor_m.fetchall()) if not run_background: - logger.info(f"{key} result {str(data)}") + logger.info(f"{key} result {str(data)}", __name__) if commit: self.connect_msql.commit() return data except Exception as e: - logger.error(str(e)) + logger.error(str(e), __name__) if self.connect_msql.open: self.connect_msql.close() return [] @@ -112,7 +112,7 @@ def close(self): if self.connect_msql is not None: self.connect_msql.close() except Exception as e: - logger.error(e) + logger.error(e, __name__) class SqlServerTool(object): @@ -147,20 +147,20 @@ def connect_execute(self, sqlconfig:SQLConfig, sqlscript:list, **kwargs): if isinstance(sqlscript, list): for ss in sqlscript: if ss != None and ss != "None" and "None" not in ss and len(ss) > 5: - logger.info(f"{key} [{sqlconfig.host}] start execute {ss}") + logger.info(f"{key} [{sqlconfig.host}] start execute {ss}", __name__) cursor_m.execute(ss) data.append(cursor_m.fetchall()) - logger.info(f"{key} result {str(data)}") + logger.info(f"{key} result {str(data)}", __name__) elif isinstance(sqlscript, str): if sqlscript != None and sqlscript != "None" and "None" not in sqlscript and len(sqlscript) > 5: - logger.info(f"{key} start [{sqlconfig.host}] execute {sqlscript}") + logger.info(f"{key} start [{sqlconfig.host}] execute {sqlscript}", __name__) cursor_m.execute(sqlscript) data.append(cursor_m.fetchall()) - logger.info(f"{key} result {str(data)}") + logger.info(f"{key} result {str(data)}", __name__) return data except Exception as e: - logger.error(str(e)) + logger.error(str(e), __name__) if self.connect_msql.open: self.connect_msql.close() return [] diff --git a/haf/common/httprequest.py b/haf/common/httprequest.py index 0e01764..978cc89 100644 --- a/haf/common/httprequest.py +++ b/haf/common/httprequest.py @@ -54,7 +54,7 @@ def get(url, data=None, headers=None, **kwargs): key = kwargs.get("key") try: url = url + HttpController.getdata(data) - logger.info(f'{key} [url] {url}') + logger.info(f'{key} [url] {url}', __name__) request = ur.Request(url=url, headers=headers, method="GET") if headers is not None: for key in headers.keys(): @@ -64,18 +64,18 @@ def get(url, data=None, headers=None, **kwargs): if response is None: return {"result": "None"} else: - logger.info(f"{key} {str(response)}") + logger.info(f"{key} {str(response)}", __name__) return response except ur.URLError as e: - logger.info(f"{key}{str(e)}") - logger.info(f"{key}{traceback.format_exc()}") + logger.info(f"{key}{str(e)}", __name__) + logger.info(f"{key}{traceback.format_exc()}", __name__) traceback.print_exc() return e except Exception as ee: traceback.print_exc() logger.info(f"{key}{str(ee)}") - logger.info(f"{key}{traceback.format_exc()}") + logger.info(f"{key}{traceback.format_exc()}", __name__) return ee @staticmethod @@ -93,19 +93,19 @@ def post(url, data=None, headers=None, **kwargs): if response is None: return {"result": "None"} else: - logger.info(f"{key} {str(response)}") + logger.info(f"{key} {str(response)}", __name__) return response except ur.URLError as e: - logger.error(f"{key} {str(e)}") + logger.error(f"{key} {str(e)}", __name__) traceback.print_exc() return e except urlerror.HTTPError as httpe: - logger.error(f"{key} { str(httpe)}") + logger.error(f"{key} { str(httpe)}", __name__) traceback.print_exc() return httpe except Exception as ee: - logger.error(f"{key} {str(ee)}") + logger.error(f"{key} {str(ee)}", __name__) traceback.print_exc() return ee @@ -120,10 +120,10 @@ def put(self, url, data=None, **kwargs): return result except ur.URLError as e: traceback.print_exc() - logger.error(f"{key} {str(e)}") + logger.error(f"{key} {str(e)}", __name__) except Exception as ee: traceback.print_exc() - logger.error(f"{key} {str(ee)}") + logger.error(f"{key} {str(ee)}", __name__) def delete(self, url, data=None): data = bytes(data, encoding='utf8') if data is not None else None @@ -135,6 +135,6 @@ def delete(self, url, data=None): data = data.encode() if data is not None else None return result except ur.URLError as e: - logger.error(str(e)) + logger.error(str(e), __name__) except Exception as ee: - logger.error(str(ee)) + logger.error(str(ee), __name__) diff --git a/haf/common/log.py b/haf/common/log.py index aec7157..615ba2b 100644 --- a/haf/common/log.py +++ b/haf/common/log.py @@ -2,35 +2,41 @@ import logging from haf.busclient import BusClient +from haf.common.sigleton import SingletonType -class BaseLogger(object): +class BaseLogger(metaclass=SingletonType): def __init__(self, logger_name): self.logger_name = logger_name self.bus_client = None - + self.process_id = 0 + + # here using this function to reconnect to the bus : loader, runner, recorder def bind_busclient(self, bus_client: BusClient): self.bus_client = BusClient(bus_client.domain, bus_client.port, bus_client.auth_key) + + def bind_process(self, process_id): + self.process_id = process_id - def debug(self, msg): - msg = {"logger_name":self.logger_name, "level":"debug", "msg": msg} + def debug(self, msg, logger_name=None): + msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"debug", "msg": msg} self.msg_write(msg) - def info(self, msg): - msg = {"logger_name":self.logger_name, "level":"info", "msg": msg} + def info(self, msg, logger_name=None): + msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"info", "msg": msg} self.msg_write(msg) - def warning(self, msg): - msg = {"logger_name":self.logger_name, "level":"warning", "msg": msg} + def warning(self, msg, logger_name=None): + msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"warning", "msg": msg} self.msg_write(msg) - def error(self, msg): - msg = {"logger_name":self.logger_name, "level":"error", "msg": msg} + def error(self, msg, logger_name=None): + msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"error", "msg": msg} self.msg_write(msg) - def critical(self, msg): - msg = {"logger_name":self.logger_name, "level":"critical", "msg": msg} + def critical(self, msg, logger_name=None): + msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"critical", "msg": msg} self.msg_write(msg) def __new__(cls, *args, **kwargs): diff --git a/haf/config.py b/haf/config.py index 4c71856..9b68db8 100644 --- a/haf/config.py +++ b/haf/config.py @@ -109,7 +109,7 @@ MAIN_VERSION = 2 SUB_VERSION = 6 -FIX_VERSION = 5 +FIX_VERSION = 6 VERSION_TYPE = "haf" PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}" diff --git a/haf/loader.py b/haf/loader.py index 661e93c..c3f87da 100644 --- a/haf/loader.py +++ b/haf/loader.py @@ -15,7 +15,7 @@ class Loader(Process): - def __init__(self, bus_client:BusClient=None): + def __init__(self, bus_client:BusClient=None, args:list=None): super().__init__() self.bus_client = bus_client self.daemon = True @@ -24,13 +24,14 @@ def __init__(self, bus_client:BusClient=None): def run(self): try: + logger.bind_process(self.pid) self.key = f"{self.pid}$%loader$%" logger.bind_busclient(self.bus_client) - logger.info(f"{self.key} start loader") + logger.info(f"{self.key} start loader", __name__) self.case_queue = self.bus_client.get_case() while True: if self.get_parameter() == SIGNAL_START: - logger.info(f"{self.key} -- get start signal from main") + logger.info(f"{self.key} -- get start signal from main", __name__) break time.sleep(0.01) @@ -49,7 +50,7 @@ def run(self): file_name = temp.get("file_name") inputs = LoadFromConfig.load_from_file(file_name) - logger.info(f"{self.key} -- {inputs}") + # logger.info(f"{self.key} -- {inputs}", __name__) input = inputs.get("config")[0] bench_name = input.get("name") module_name = input.get("module_name") @@ -93,8 +94,8 @@ def run(self): self.put_web_message("web") time.sleep(0.01) except Exception as e: - logger.error(f"{self.key} {e}") - logger.error(f"{self.key} {FailLoaderException}") + logger.error(f"{self.key} {e}", __name__) + logger.error(f"{self.key} {FailLoaderException}", __name__) self.end_handler(e) def get_parameter(self, param_key=None): @@ -121,18 +122,18 @@ def put_web_message(self, key:str): @locker def put_case(self, key:str, case): - logger.info(f"{self.key} -- put case {case.bench_name} - {case.ids.id}.{case.ids.subid}.{case.ids.name}") + logger.info(f"{self.key} -- put case {case.bench_name} - {case.ids.id}.{case.ids.subid}.{case.ids.name}", __name__) self.case_queue.put(case) def end_handler(self, error=None): try: if error: - logger.error(f"{self.key} end loader with Error - {error}") + logger.error(f"{self.key} end loader with Error - {error}", __name__) else: - logger.info(f"{self.key} end loader") + logger.info(f"{self.key} end loader", __name__) self.case_queue.put(SIGNAL_CASE_END) except Exception as e: - logger.error(f"{self.key} {e}") + logger.error(f"{self.key} {e}", __name__) class LoadFromConfig(object): diff --git a/haf/logger.py b/haf/logger.py index e0d90ec..53f1163 100644 --- a/haf/logger.py +++ b/haf/logger.py @@ -4,9 +4,8 @@ from multiprocessing import Process from haf.busclient import BusClient from haf.config import * -from haf.common.log import Log -logger = Log.getLogger(__name__) +logger = logging.getLogger(__name__) class Logger(Process): @@ -18,14 +17,16 @@ def __init__(self, case_name, log_dir, bus_client: BusClient): self.log_dir = log_dir self.loggers = {} + def reconnect_bus(self): + self.bus_client = BusClient(self.bus_client.domain, self.bus_client.port, self.bus_client.auth_key) + def run(self): - logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s <%(process)d> [%(name)s] %(message)s') - logger.bind_busclient(self.bus_client) - logger.info("start system logger") + self.reconnect_bus() + logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s') log_home = f"{self.log_dir}/{self.case_name}" if not os.path.exists(log_home): os.makedirs(log_home) - # here delete BusClient(), using input bus_client + # here delete BusClient(), using input bus_clients # self.bus_client = BusClient() try: log_queue = self.bus_client.get_log() @@ -47,11 +48,12 @@ def split_log(self, log): def log_print(self, log): logger_name = log.get("logger_name") level = log.get("level") - msg = log.get("msg") - if logger_name not in self.loggers: - self.loggers[logger_name] = logging.getLogger(logger_name) - - logger = self.loggers.get(logger_name) + msg_origin = log.get("msg") + process = log.get("process") + if process not in self.loggers: + self.loggers[process] = logging.getLogger(logger_name) + logger = self.loggers.get(process) + msg = f"<{process}> [{logger_name}] {msg_origin}" if level=="debug": logger.debug(msg) elif level=="info": diff --git a/haf/program.py b/haf/program.py index 463e0e6..a45abae 100644 --- a/haf/program.py +++ b/haf/program.py @@ -22,7 +22,7 @@ from haf.runner import Runner from haf.utils import Utils -logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s <%(process)d> [%(name)s] %(message)s') +logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s [%(name)s] <%(process)d> %(message)s') logger = logging.getLogger(__name__) @@ -54,7 +54,7 @@ def _start_loader(self, count: int, bus_client: BusClient): :return: None ''' for x in range(count): - loader = Loader(bus_client) + loader = Loader(bus_client, self.args) loader.start() time.sleep(0.1) @@ -76,7 +76,7 @@ def _start_recorder(self, bus_client: BusClient, sql_config: SQLConfig=None, sql time.sleep(0.1) def _init_logging_module(self, args): - logging.basicConfig(level=logging.INFO if not args.debug else logging.DEBUG, format='%(asctime)s %(levelname)s <%(process)d> [%(name)s] %(message)s') + logging.basicConfig(level=logging.INFO if not args.debug else logging.DEBUG, format='%(asctime)s %(levelname)s [%(name)s] %(message)s') pass def _init_system_logger(self, log_dir: str, bus_client: BusClient): diff --git a/haf/recorder.py b/haf/recorder.py index febaf92..9d138ed 100644 --- a/haf/recorder.py +++ b/haf/recorder.py @@ -55,7 +55,8 @@ def run(self): self.on_recorder_start() self.recorder_key = f"{self.pid}$%recorder$%" logger.bind_busclient(self.bus_client) - logger.info(f"{self.recorder_key} start recorder ") + logger.bind_process(self.pid) + logger.info(f"{self.recorder_key} start recorder ", __name__) #self.bus_client = BusClient() self.results_handler = self.bus_client.get_result() self.publish_result = self.bus_client.get_publish_result() @@ -64,10 +65,10 @@ def run(self): result = self.results_handler.get() if isinstance(result, (HttpApiResult, AppResult, WebResult)): if isinstance(result.case, (HttpApiCase, BaseCase, PyCase, WebCase, AppCase)): - logger.info(f"{self.recorder_key} recorder--{result.case.bench_name}.{result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name} is {result.result}") + logger.info(f"{self.recorder_key} {result.case.bench_name}.{result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name} is {RESULT_GROUP.get(str(result.result), None)}", __name__) else: - logger.info(f"{self.recorder_key} recorder ! wrong result!") - logger.info(f"{self.recorder_key} recorder {result.run_error}") + logger.info(f"{self.recorder_key} recorder ! wrong result!", __name__) + logger.info(f"{self.recorder_key} recorder {result.run_error}", __name__) self.result_handler(result) elif result == SIGNAL_RESULT_END: self.signal_end_count += 1 @@ -102,7 +103,7 @@ def end_handler(self): self.generate_report() self.show_in_cs() self.publish_to_mysql() - logger.info(f"{self.recorder_key} end recorder") + logger.info(f"{self.recorder_key} end recorder", __name__) self.send_record_end_signal() def send_record_end_signal(self): @@ -167,7 +168,6 @@ def add_result_to_suite(self, result): self.results.details[result.case.bench_name] = suite def result_handler(self, result): - logger.info(f"{self.recorder_key} from {result.begin_time} to {result.end_time}, result is {RESULT_GROUP.get(str(result.result), None)}") self.add_result_to_suite(result) self.check_case_result(result) self.publish_results() @@ -183,23 +183,23 @@ def show_in_cs(self): result_summary = "|{:^8}|{:^8}|{:^8}|{:^8}|{:^8}|".format(self.results.passed, self.results.failed, self.results.skip, self.results.error, \ self.results.all) - logger.info("----------------------------------------------") - logger.info("|--\33[32mPASS\33[0m--|--\33[31mFAIL\33[0m--|--\33[37mSKIP\33[0m--|--\33[35mERROR\33[0m-|---\33[36mALL\33[0m--|") - logger.info(result_summary) - logger.info("----------------------------------------------") + logger.info("----------------------------------------------", __name__) + logger.info("|--\33[32mPASS\33[0m--|--\33[31mFAIL\33[0m--|--\33[37mSKIP\33[0m--|--\33[35mERROR\33[0m-|---\33[36mALL\33[0m--|", __name__) + logger.info(result_summary, __name__) + logger.info("----------------------------------------------", __name__) def publish_to_mysql(self): ''' publish results to mysql database ''' if self.sql_publish: - logger.info(f"publish results {self.results} to mysql!") + logger.info(f"publish results {self.results} to mysql!", __name__) import_ok = False try: from hafsqlpublish.publish import Publish import_ok = True except Exception as e: - logger.error("Plugin hafsqlpublish is not installed, using 'pip install hafsqlpublish -U' to install") + logger.error("Plugin hafsqlpublish is not installed, using 'pip install hafsqlpublish -U' to install", __name__) if import_ok: publish = Publish(self.sql_config) publish.publish_result(self.results) diff --git a/haf/runner.py b/haf/runner.py index e5b6300..46acbae 100644 --- a/haf/runner.py +++ b/haf/runner.py @@ -54,7 +54,7 @@ def get_bench(self, case:BaseCase): @locker def put_result(self, key:str, result:HttpApiResult): - logger.info(f"{self.key} : runner {self.pid} put result {result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name}") + logger.info(f"{self.key} : runner {self.pid} put result {result.case.ids.id}.{result.case.ids.subid}.{result.case.ids.name}", __name__) self.result_handler_queue.put(result) @locker @@ -67,7 +67,7 @@ def put_web_message(self, key:str): # TODO: try new_locker here, still need some tests # @locker def put_case_back(self, key:str, case): - logger.info(f"{self.runner_key} : runner put case {case.ids.id}.{case.ids.subid}-{case.ids.name}") + logger.info(f"{self.runner_key} : runner put case {case.ids.id}.{case.ids.subid}-{case.ids.name}", __name__) with new_locker(self.bus_client, key): self.case_handler_queue.put(case) @@ -100,7 +100,8 @@ def run(self): self.runner_key = f"{self.pid}$%runner$%" self.runner["key"] = f"{self.pid}" logger.bind_busclient(self.bus_client) - logger.info(f"{self.runner_key} start runner") + logger.bind_process(self.pid) + logger.info(f"{self.runner_key} start runner", __name__) self.web_queue = self.bus_client.get_publish_runner() self.case_handler_queue = self.bus_client.get_case() self.result_handler_queue = self.bus_client.get_result() @@ -135,7 +136,7 @@ def run(self): loop.close() self.end_handler() except Exception as e: - logger.error(f"{self.key} : {e}") + logger.error(f"{self.key} : {e}", __name__) raise FailRunnerException async def run_cases(self, local_cases): @@ -157,7 +158,7 @@ async def run_case(self, local_case): try: try: self.key = local_case.log_key - logger.info(f"{self.key} : runner {self.pid} -- get {local_case.ids.id}.{local_case.ids.subid}-{local_case.ids.name}") + logger.info(f"{self.key} : runner {self.pid} -- get {local_case.ids.id}.{local_case.ids.subid}-{local_case.ids.name}", __name__) self.result_handler(local_case) self.init_runner(local_case) if local_case.type == CASE_TYPE_HTTPAPI: @@ -182,18 +183,18 @@ async def run_case(self, local_case): self.result_handler(result) return result except Exception as runerror: - logger.error(f"{self.key} : {runerror}") + logger.error(f"{self.key} : {runerror}", __name__) result.run_error = traceback.format_exc() result.result = RESULT_ERROR return result except Exception as e: - logger.error(f"{self.key} : {e}") + logger.error(f"{self.key} : {e}", __name__) result.run_error = traceback.format_exc() result.result = RESULT_ERROR return result def end_handler(self): - logger.info(f"{self.runner_key} : end runner") + logger.info(f"{self.runner_key} : end runner", __name__) self.result_handler_queue.put(SIGNAL_RESULT_END) self.case_handler_queue.put(SIGNAL_CASE_END) @@ -241,7 +242,7 @@ async def run(self, case:PyCase): return [CASE_SKIP, result] result.case = case - logger.info(f"{self.key} : PyRunner run - {case.bench_name} {case.ids.id}.{case.ids.subid}-{case.ids.name}") + logger.info(f"{self.key} : PyRunner run - {case.bench_name} {case.ids.id}.{case.ids.subid}-{case.ids.name}", __name__) suite = HttpApiSuite() try: module_name = case.module_name @@ -260,14 +261,14 @@ async def run(self, case:PyCase): except AssertionError as ae: case.response = getattr(suite, "response", Response()) traceback.print_exc() - logger.error(f"{self.key} : {traceback.format_exc()}") + logger.error(f"{self.key} : {traceback.format_exc()}", __name__) result.result = RESULT_FAIL result.run_error = traceback.format_exc() result.on_case_end() return result except Exception as e: traceback.print_exc() - logger.error(f"{self.key} : {traceback.format_exc()}") + logger.error(f"{self.key} : {traceback.format_exc()}", __name__) result.result = RESULT_ERROR result.run_error = traceback.format_exc() result.on_case_end() @@ -304,7 +305,7 @@ async def run(self, case:HttpApiCase): result.result = RESULT_SKIP return [CASE_SKIP, result] - logger.info(f"{self.key} : ApiRunner run - {case.ids.id}.{case.ids.subid}-{case.ids.name}") + logger.info(f"{self.key} : ApiRunner run - {case.ids.id}.{case.ids.subid}-{case.ids.name}", __name__) try: result.case = case case.response = self.request(case.request) @@ -317,7 +318,7 @@ async def run(self, case:HttpApiCase): result.case = case result.result = RESULT_PASS if False not in result.result_check_response and result.result_check_sql_response is True else RESULT_FAIL except Exception as e: - logger.error(f"{self.key} : {e}") + logger.error(f"{self.key} : {e}", __name__) result.run_error = e result.result = RESULT_ERROR result.on_case_end() @@ -356,17 +357,17 @@ def check_sql_response(self, case:HttpApiCase): if case.expect.sql_check_func is None or case.expect.sql_response_result is None: return [True, "ok"] data = case.response.body - logger.info(f"{self.key} : check sql response : {case.expect.sql_check_func}") + logger.info(f"{self.key} : check sql response : {case.expect.sql_check_func}", __name__) class_content = importlib.import_module(case.expect.sql_check_func[0]) check_func = getattr(getattr(class_content, case.expect.sql_check_func[1]), case.expect.sql_check_func[2]) - logger.info(f"{self.key} : check func : {check_func}") - logger.info(f"{self.key} : check list is {case.sqlinfo.check_list}") + logger.info(f"{self.key} : check func : {check_func}", __name__) + logger.info(f"{self.key} : check list is {case.sqlinfo.check_list}", __name__) if case.sqlinfo.check_list is not None: check_func(case.expect.sql_response_result, data, case.sqlinfo.check_list["sql_response"]) else: check_func(case.expect.sql_response_result, data) except Exception as e: - logger.error(f"{self.key} : {e}") + logger.error(f"{self.key} : {e}", __name__) traceback.print_exc() return [False, traceback.format_exc()] return result @@ -394,13 +395,13 @@ def wait_activity(self, activity, timeout, driver): try: i = 0 while ilist: data = func_obj.connect_execute(sqlconfig, sqlscript, **kwargs) return data except Exception as e: - logger.info(f"{key} {e}") + logger.info(f"{key} {e}", __name__) finally: - logger.info(f"{key} {func_obj}") + logger.info(f"{key} {func_obj}", __name__) if func_obj is not None: func_obj.close() @@ -59,7 +59,7 @@ def get_rows_from_xlsx(filename: str)->dict: if not filename.endswith("xlsx"): return {} if not os.path.exists(filename): - logger.error("{} not fount file : {}".format("system$%util$%", filename)) + logger.error("{} not fount file : {}".format("system$%util$%", filename), __name__) raise FileNotFoundError try: header = [] @@ -77,7 +77,7 @@ def get_rows_from_xlsx(filename: str)->dict: xlsx = load_workbook(filename) sheet_names = xlsx.sheetnames if "testcases" not in sheet_names or "config" not in sheet_names: - logger.log(f"not fount sheet in {filename}") + logger.log(f"not fount sheet in {filename}", __name__) return {} testcases = xlsx["testcases"].rows config = xlsx["config"].rows @@ -114,7 +114,7 @@ def get_rows_from_xlsx(filename: str)->dict: result["dbconfig"].append(dict(zip(dbconfig_header, d))) return result except Exception as e: - logger.error(f"{filename} {e} ") + logger.error(f"{filename} {e} ", __name__) @staticmethod def load_from_json(file_name: str)->dict: @@ -132,7 +132,7 @@ def load_from_json(file_name: str)->dict: else: raise FileNotFoundError except Exception as e: - logger.error(f"{file_name} {e} ") + logger.error(f"{file_name} {e} ", __name__) @staticmethod def load_from_yml(file_name: str)-> dict: @@ -150,7 +150,7 @@ def load_from_yml(file_name: str)-> dict: else: raise FileNotFoundError except Exception as e: - logger.error(f"{file_name} {e} ") + logger.error(f"{file_name} {e} ", __name__) @staticmethod def get_path(path): @@ -261,7 +261,7 @@ def load_from_py(file_name: str)->dict: py_config = {} py_config["config"] = [] config_temp = {} - logger.info("{} found python file : {}".format("system$%util$%", file_name)) + logger.info("{} found python file : {}".format("system$%util$%", file_name), __name__) if os.path.exists(file_name): path, file = Utils.get_path(file_name) sys.path.append(path) @@ -289,8 +289,8 @@ def load_from_py(file_name: str)->dict: } except Exception as e: - logger.error(f"{file_name} {e} ") - logger.error(f"{file_name} {traceback.format_exc()}") + logger.error(f"{file_name} {e} ", __name__) + logger.error(f"{file_name} {traceback.format_exc()}", __name__) @staticmethod def http_request(request:Request, **kwargs) : @@ -315,7 +315,7 @@ def http_request(request:Request, **kwargs) : if method == CASE_HTTP_API_METHOD_PUT: result = HttpController.put(url, data, header) - logger.info("{} {}".format(key, result)) + logger.info("{} {}".format(key, result), __name__) if isinstance(result, HTTPResponse): response.header = result.headers try: @@ -328,7 +328,7 @@ def http_request(request:Request, **kwargs) : response.code = result.code if hasattr(result, "code") else None response.header = result.info() if hasattr(result, "info") else None - logger.info(f"{key} {result}") + logger.info(f"{key} {result}", __name__) return response @staticmethod