In Flask: How to access app Logger within Blueprint

PythonLoggingFlask

Python Problem Overview


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

Python Solutions


Solution 1 - Python

inside the blueprint add:

from flask import current_app

and when needed call:

current_app.logger.info('grolsh')

Solution 2 - Python

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")
    ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGal BrachaView Question on Stackoverflow
Solution 1 - PythonGal BrachaView Answer on Stackoverflow
Solution 2 - PythonsuzanshakyaView Answer on Stackoverflow