use app.name as app.logger name

This commit is contained in:
David Lord 2019-07-01 14:56:18 -07:00
parent 465da9f610
commit df470aecb9
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
8 changed files with 40 additions and 25 deletions

View file

@ -653,22 +653,26 @@ class Flask(_PackageBoundObject):
@locked_cached_property
def logger(self):
"""The ``'flask.app'`` logger, a standard Python
:class:`~logging.Logger`.
"""A standard Python :class:`~logging.Logger` for the app, with
the same name as :attr:`name`.
In debug mode, the logger's :attr:`~logging.Logger.level` will be set
to :data:`~logging.DEBUG`.
In debug mode, the logger's :attr:`~logging.Logger.level` will
be set to :data:`~logging.DEBUG`.
If there are no handlers configured, a default handler will be added.
See :ref:`logging` for more information.
If there are no handlers configured, a default handler will be
added. See :doc:`/logging` for more information.
.. versionchanged:: 1.0
.. versionchanged:: 1.1.0
The logger takes the same name as :attr:`name` rather than
hard-coding ``"flask.app"``.
.. versionchanged:: 1.0.0
Behavior was simplified. The logger is always named
``flask.app``. The level is only set during configuration, it
doesn't check ``app.debug`` each time. Only one format is used,
not different ones depending on ``app.debug``. No handlers are
removed, and a handler is only added if no handlers are already
configured.
``"flask.app"``. The level is only set during configuration,
it doesn't check ``app.debug`` each time. Only one format is
used, not different ones depending on ``app.debug``. No
handlers are removed, and a handler is only added if no
handlers are already configured.
.. versionadded:: 0.3
"""

View file

@ -57,7 +57,10 @@ default_handler.setFormatter(
def create_logger(app):
"""Get the ``'flask.app'`` logger and configure it if needed.
"""Get the the Flask apps's logger and configure it if needed.
The logger name will be the same as
:attr:`app.import_name <flask.Flask.name>`.
When :attr:`~flask.Flask.debug` is enabled, set the logger level to
:data:`logging.DEBUG` if it is not set.
@ -66,7 +69,7 @@ def create_logger(app):
:class:`~logging.StreamHandler` for
:func:`~flask.logging.wsgi_errors_stream` with a basic format.
"""
logger = logging.getLogger("flask.app")
logger = logging.getLogger(app.name)
if app.debug and logger.level == logging.NOTSET:
logger.setLevel(logging.DEBUG)