I want my web app to write all logs in single uniform format. There are several plugged modules and gunicorn besides that have their own handlers with own format.
I figured out how to drop the handlers from all existing loggers except root and to propagate all messages to root. It works, but I don't suspect it's not the best way. Are there better ways to do this?
logging.basicConfig(
handlers=[my_handler],
level=log_level,
)
root_logger = logging.getLogger()
for _, logger in root_logger.manager.loggerDict.items():
logger.handlers = []
logger.propagate = True