use app.name as app.logger name
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 465da9f · Browse files · 8 files·+40 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+40 added−25 removed
- tests:+5 added−3 removed
- other:+35 added−22 removed
Provenance
- Commit
df470ae- Tree
19844f0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
465da9f
8 files changed+40 added−25 removed
modified:docs/config.rst+1 added-1 removed
380 unmodified lines381 ``LOGGER_HANDLER_POLICY``, ``EXPLAIN_TEMPLATE_LOADING``382 383 .. versionchanged:: 1.0384 ``LOGGER_NAME`` and ``LOGGER_HANDLER_POLICY`` were removed. See385- :ref:`logging` for information about configuration.385+ :doc:`/logging` for information about configuration.386 387 Added :data:`ENV` to reflect the :envvar:`FLASK_ENV` environment388 variable.389 308 unmodified linesmodified:docs/errorhandling.rst+1 added-1 removed
229 unmodified lines230 231 Logging232 -------233 234-See :ref:`logging` for information on how to log exceptions, such as by234+See :doc:`/logging` for information on how to log exceptions, such as by235 emailing them to admins.236 237 238 Debugging Application Errors59 unmodified linesmodified:docs/logging.rst+6 added-6 removed
1-.. _logging:2-1 Logging2 =======3 6-Flask uses standard Python :mod:`logging`. All Flask-related messages are7-logged under the ``'flask'`` logger namespace.8-:meth:`Flask.logger <flask.Flask.logger>` returns the logger named9-``'flask.app'``, and can be used to log messages for your application. ::4+Flask uses standard Python :mod:`logging`. Messages about your Flask5+application are logged with :meth:`app.logger <flask.Flask.logger>`,6+which takes the same name as :attr:`app.name <flask.Flask.name>`. This7+logger can also be used to log your own messages.8 9+.. code-block:: python10+11 @app.route('/login', methods=['POST'])12 def login():13 user = get_user(request.form['username'])14 166 unmodified linesmodified:src/flask/app.py+16 added-12 removed
651 unmodified lines652 return self.debug653 654 @locked_cached_property655 def logger(self):656- """The ``'flask.app'`` logger, a standard Python657- :class:`~logging.Logger`.656+ """A standard Python :class:`~logging.Logger` for the app, with657+ the same name as :attr:`name`.658 659- In debug mode, the logger's :attr:`~logging.Logger.level` will be set660- to :data:`~logging.DEBUG`.659+ In debug mode, the logger's :attr:`~logging.Logger.level` will660+ be set to :data:`~logging.DEBUG`.661 662- If there are no handlers configured, a default handler will be added.663- See :ref:`logging` for more information.662+ If there are no handlers configured, a default handler will be663+ added. See :doc:`/logging` for more information.664 665- .. versionchanged:: 1.0665+ .. versionchanged:: 1.1.0666+ The logger takes the same name as :attr:`name` rather than667+ hard-coding ``"flask.app"``.668+669+ .. versionchanged:: 1.0.0670 Behavior was simplified. The logger is always named667- ``flask.app``. The level is only set during configuration, it668- doesn't check ``app.debug`` each time. Only one format is used,669- not different ones depending on ``app.debug``. No handlers are670- removed, and a handler is only added if no handlers are already671- configured.671+ ``"flask.app"``. The level is only set during configuration,672+ it doesn't check ``app.debug`` each time. Only one format is673+ used, not different ones depending on ``app.debug``. No674+ handlers are removed, and a handler is only added if no675+ handlers are already configured.676 677 .. versionadded:: 0.3678 """679 return create_logger(self)1787 unmodified linesmodified:src/flask/logging.py+5 added-2 removed
55 unmodified lines56 )57 58 59 def create_logger(app):60- """Get the ``'flask.app'`` logger and configure it if needed.60+ """Get the the Flask apps's logger and configure it if needed.61 62+ The logger name will be the same as63+ :attr:`app.import_name <flask.Flask.name>`.64+65 When :attr:`~flask.Flask.debug` is enabled, set the logger level to66 :data:`logging.DEBUG` if it is not set.67 68 If there is no handler for the logger's effective level, add a69 :class:`~logging.StreamHandler` for70 :func:`~flask.logging.wsgi_errors_stream` with a basic format.71 """69- logger = logging.getLogger("flask.app")72+ logger = logging.getLogger(app.name)73 74 if app.debug and logger.level == logging.NOTSET:75 logger.setLevel(logging.DEBUG)76 4 unmodified linesmodified:tests/test_logging.py+2 added-2 removed
21 unmodified lines22 root_handlers = logging.root.handlers[:]23 logging.root.handlers = []24 root_level = logging.root.level25 26- logger = logging.getLogger("flask.app")26+ logger = logging.getLogger("flask_test")27 logger.handlers = []28 logger.setLevel(logging.NOTSET)29 30 logging_plugin = pytestconfig.pluginmanager.unregister(name="logging-plugin")10 unmodified lines41 pytestconfig.pluginmanager.register(logging_plugin, "logging-plugin")42 43 44 def test_logger(app):45- assert app.logger.name == "flask.app"45+ assert app.logger.name == "flask_test"46 assert app.logger.level == logging.NOTSET47 assert app.logger.handlers == [default_handler]48 49 57 unmodified linesmodified:tests/test_templating.py+3 added-1 removed
428 unmodified lines429 assert "See http://flask.pocoo.org/docs/blueprints/#templates" in text430 431 with app.test_client() as c:432 monkeypatch.setitem(app.config, "EXPLAIN_TEMPLATE_LOADING", True)433- monkeypatch.setattr(logging.getLogger("flask"), "handlers", [_TestHandler()])433+ monkeypatch.setattr(434+ logging.getLogger("blueprintapp"), "handlers", [_TestHandler()]435+ )436 437 with pytest.raises(TemplateNotFound) as excinfo:438 c.get("/missing")439 14 unmodified linesmodified:CHANGES.rst+6 added
16 unmodified lines17 18 - :meth:`Flask.finalize_request` is called for all unhandled19 exceptions even if there is no ``500`` error handler.20 21+- :attr:`Flask.logger` takes the same name as22+ :attr:`Flask.name` (the value passed as23+ ``Flask(import_name)``. This reverts 1.0's behavior of always24+ logging to ``"flask.app"``, in order to support multiple apps in the25+ same process. This may require adjusting logging configuration.26+ :issue:`2866`.27 - :meth:`flask.RequestContext.copy` includes the current session28 object in the request context copy. This prevents ``session``29 pointing to an out-of-date object. :issue:`2935`30 - Using built-in RequestContext, unprintable Unicode characters in958 unmodified lines