mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-17 10:55:14 +02:00
Implement logging strategy (#444)
* Logging strategy and convert all prints() to logging invocations
This commit is contained in:
parent
3e0651222b
commit
dd70aade11
117 changed files with 1216 additions and 667 deletions
|
|
@ -11,9 +11,13 @@ import importlib
|
|||
|
||||
from .. log_level import LogLevel
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def fn(module_name, class_name, params, w):
|
||||
|
||||
print(f"Starting {module_name}...")
|
||||
logger.info(f"Starting {module_name}...")
|
||||
|
||||
if "log_level" in params:
|
||||
params["log_level"] = LogLevel(params["log_level"])
|
||||
|
|
@ -22,7 +26,7 @@ def fn(module_name, class_name, params, w):
|
|||
|
||||
try:
|
||||
|
||||
print(f"Starting {class_name} using {module_name}...")
|
||||
logger.info(f"Starting {class_name} using {module_name}...")
|
||||
|
||||
module = importlib.import_module(module_name)
|
||||
class_object = getattr(module, class_name)
|
||||
|
|
@ -30,16 +34,16 @@ def fn(module_name, class_name, params, w):
|
|||
processor = class_object(**params)
|
||||
|
||||
processor.run()
|
||||
print(f"{module_name} stopped.")
|
||||
logger.info(f"{module_name} stopped.")
|
||||
|
||||
except Exception as e:
|
||||
print("Exception:", e)
|
||||
logger.error("Exception occurred", exc_info=True)
|
||||
|
||||
print("Restarting in 10...")
|
||||
logger.info("Restarting in 10...")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
print("Closing")
|
||||
logger.info("Closing")
|
||||
w.close()
|
||||
|
||||
class Processing:
|
||||
|
|
@ -108,7 +112,7 @@ class Processing:
|
|||
readers.remove(r)
|
||||
wait_for -= 1
|
||||
|
||||
print("All processes exited")
|
||||
logger.info("All processes exited")
|
||||
|
||||
for p in procs:
|
||||
p.join()
|
||||
|
|
@ -169,13 +173,12 @@ def run():
|
|||
|
||||
p.run()
|
||||
|
||||
print("Finished.")
|
||||
logger.info("Finished.")
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
print("Will retry...", flush=True)
|
||||
logger.error("Exception occurred, will retry...", exc_info=True)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue