In Flask: How to access app Logger within Blueprint

Question:

What is the standard way for a blueprint to access the application logger?

Asked By: Gal Bracha

||

Answers:

Inside the blueprint add:

from flask import current_app

and when needed, call:

current_app.logger.info('grolsh')
Answered By: Gal Bracha

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")
    ...
Answered By: suzanshakya
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.