IN a Rest API server I am using logging module to logs the script run and to send the result to th client. I am using a logging with a file global handler and a single stream handler. The Http response depends by the number of errors and critical in logger. IN order to count logger and error I am using a custom version of logger.
Inspired by this post I wrote the following code in order to count the times a method is called
def init_logger(lid: str):
log = MyLogger(str(lid))
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)
log.setLevel(logging.DEBUG)
return log
The problem is that if I init two different logger with different id the counting is overlapped as showed below
log1 = init_logger(1)
log2 = init_logger(2)
log1.info("INFO 1")
print(log2.info.called) -->1