blakeblackshear.frigate/frigate/log.py

27 lines
846 B
Python
Raw Normal View History

2020-11-04 04:26:39 +01:00
# adapted from https://medium.com/@jonathonbao/python3-logging-with-multiprocessing-f51f460b8778
import logging
import threading
from logging import handlers
def listener_configurer():
root = logging.getLogger()
console_handler = logging.StreamHandler()
2020-11-04 13:28:07 +01:00
formatter = logging.Formatter('%(threadName)-25s %(name)-16s %(levelname)-8s: %(message)s')
2020-11-04 04:26:39 +01:00
console_handler.setFormatter(formatter)
root.addHandler(console_handler)
root.setLevel(logging.INFO)
def root_configurer(queue):
h = handlers.QueueHandler(queue)
root = logging.getLogger()
root.addHandler(h)
root.setLevel(logging.INFO)
def log_process(queue):
2020-11-04 13:28:07 +01:00
threading.current_thread().name = f"logger"
2020-11-04 04:26:39 +01:00
listener_configurer()
while True:
record = queue.get()
logger = logging.getLogger(record.name)
logger.handle(record)