In Flask: How to access app Logger within Blueprint
Solution 1
inside the blueprint add:
from flask import current_app
and when needed call:
current_app.logger.info('grolsh')
Solution 2
Btw, I use this pattern:
# core.py
from werkzeug.local import LocalProxy
from flask import current_app
logger = LocalProxy(lambda: current_app.logger)
# views.py
from core import logger
@mod.route("/")
def index():
logger.info("serving index")
...
Gal Bracha
Developing for Positive Impact. Helping communities and individuals make a better world. Current Project Genetics and AI https://emedgene.com/ Open source: A platform to organize a community in a decentralized way https://github.com/Metaburn/doocrate/ https://website.doocrate.com A platform to plan co-created art funds: http://dreams.midburnerot.com/?lang=en https://github.com/metaburn/dreams/ Fluid dynamics: https://github.com/rootux/visionquest - Real-time GPU based fluid dynamic system that translates data from a depth sensor /high-speed camera. Other social accounts Facebook Twitter Linkedin Medium My old blog posts
Updated on July 08, 2022Comments
-
Gal Bracha almost 2 years
What is the standard way for a blueprint to access the application logger?