What is the standard way for a blueprint to access the application logger?
To start with logging in Flask, first import the logging module from Python. This logger module comes out of the box from the Python installation and does not need configuration. The Python logging module logs events based on pre-defined levels. The recorded log events are known as log records.
To use any Flask Blueprint, you have to import it and then register it in the application using register_blueprint() .
inside the blueprint add:
from flask import current_app
and when needed call:
current_app.logger.info('grolsh')
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") ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With