Give each util.Process their own logger

This will help to reduce boilerplate in subclasses.
This commit is contained in:
George Tsiamasiotis 2024-10-03 19:19:42 +03:00
parent 9792136950
commit 70d732ad36

View File

@ -49,6 +49,8 @@ class BaseProcess(mp.Process):
class Process(BaseProcess): class Process(BaseProcess):
logger: logging.Logger
@property @property
def stop_event(self) -> threading.Event: def stop_event(self) -> threading.Event:
# Lazily create the stop_event. This allows the signal handler to tell if anyone is # Lazily create the stop_event. This allows the signal handler to tell if anyone is
@ -74,6 +76,8 @@ class Process(BaseProcess):
signal.signal(signal.SIGTERM, receiveSignal) signal.signal(signal.SIGTERM, receiveSignal)
signal.signal(signal.SIGINT, receiveSignal) signal.signal(signal.SIGINT, receiveSignal)
self.logger = logging.getLogger(self.name)
if self.__log_queue: if self.__log_queue:
logging.basicConfig(handlers=[], force=True) logging.basicConfig(handlers=[], force=True)
logging.getLogger().addHandler(QueueHandler(self.__log_queue)) logging.getLogger().addHandler(QueueHandler(self.__log_queue))