Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created January 26, 2019 12:38
Show Gist options
  • Save lotusirous/9d5c942c154077f845b4b03413d48751 to your computer and use it in GitHub Desktop.
Save lotusirous/9d5c942c154077f845b4b03413d48751 to your computer and use it in GitHub Desktop.
Example of flask blueprint and register logging to root logger
import logging
from flask import Flask
from werkzeug.utils import find_modules, import_string
def configure_logging():
# register root logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('werkzeug').setLevel(logging.INFO)
def register_blueprints(app):
"""Automagically register all blueprint packages
Just take a look in the blueprints directory.
"""
for name in find_modules('blueprints', recursive=True):
mod = import_string(name)
if hasattr(mod, 'bp'):
app.register_blueprint(mod.bp)
return None
def create_app():
app = Flask(__name__)
configure_logging()
register_blueprints(app)
return app
if __name__ == '__main__':
app = create_app()
app.run()
import logging
from flask.blueprints import Blueprint
LOG = logging.getLogger(__name__)
bp = Blueprint("blog", __name__, url_prefix="/blog")
@bp.route("/")
def health():
LOG.debug("Call health ok")
return "Ok"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment