I have exposed a route in my Sanic app to set the log-level based on the client call. E.g.
from sanic.log import logger, logging @route("/main") async def sanic_main(request): logger.info("Info mesg") logger.debug("Debug mesg") return json("processed") @route("/setlevel") async def setlevel(request): level = request.json["level"] if level == "info": loglevel = logging.INFO elif level == "debug": loglevel = logging.DEBUG logger.setLevel(loglevel) return json("done")
On setting log levels between DEBUG and INFO, however, I am observing flaky behavior where the DEBUG messages (from “/main”) get printed only some times and vice versa.
NOTE: I am running multiple Sanic workers
How should I go about dynamically setting the log level?