Avoid duplicated logging in python/flask
There is a tricky "feature" in python's logging module. Let's explore it.
Considering the code below
import logging
main_logger = logging.getLogger("mywebapp")
controllers_logger = logging.getLogger("mywebapp.controllers")
models_logger = logging.getLogger("mywebapp.models")
That is really cool for having separate loggers under the same mywebapp
namespace, the trick is that when setting up logging, you must set up only the topmost item in the hierarchy:
main_logger.addHandler(some_handler)
make sure to not add handlers to the controllers_logger
or to the models_logger
Written by Gabriel Falcão
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#