Fixed #30934 -- Included database alias in django.db.backends log messages.

This is useful when working with database routing as you want to know
where each query is being executed.

Co-authored-by: David Winterbottom <david.winterbottom@gmail.com>
This commit is contained in:
Nick Pope 2021-07-02 14:36:53 +01:00 committed by GitHub
parent 313c3d1aa1
commit fa35c8bdbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 3 deletions

View file

@ -178,6 +178,7 @@ Messages to this logger have the following extra context:
* ``duration``: The time taken to execute the SQL statement.
* ``sql``: The SQL statement that was executed.
* ``params``: The parameters that were used in the SQL call.
* ``alias``: The alias of the database used in the SQL call.
For performance reasons, SQL logging is only enabled when
``settings.DEBUG`` is set to ``True``, regardless of the logging
@ -188,6 +189,10 @@ This logging does not include framework-level initialization (e.g.
``COMMIT``, and ``ROLLBACK``). Turn on query logging in your database if you
wish to view all database queries.
.. versionchanged:: 4.0
The database ``alias`` was added to log messages.
.. _django-security-logger:
``django.security.*``

View file

@ -226,7 +226,8 @@ Internationalization
Logging
~~~~~~~
* ...
* The alias of the database used in an SQL call is now passed as extra context
along with each message to the :ref:`django-db-logger` logger.
Management Commands
~~~~~~~~~~~~~~~~~~~