1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #26157 #25321 -- Added sql/params to extra context of schema logger

Thanks Akshesh Doshi for the initial patch and Tim Graham for the review
This commit is contained in:
Markus Holtermann
2016-03-14 21:38:38 +11:00
parent d0fe6c9156
commit 1cb65b8a77
4 changed files with 32 additions and 3 deletions

View File

@@ -99,7 +99,7 @@ class BaseDatabaseSchemaEditor(object):
Executes the given SQL statement, with optional parameters.
"""
# Log the command we're running, then run it
logger.debug("%s; (params %r)", sql, params)
logger.debug("%s; (params %r)", sql, params, extra={'params': params, 'sql': sql})
if self.collect_sql:
ending = "" if sql.endswith(";") else ";"
if params is not None:

View File

@@ -502,7 +502,7 @@ class ignore_warnings(TestContextDecorator):
@contextmanager
def patch_logger(logger_name, log_level):
def patch_logger(logger_name, log_level, log_kwargs=False):
"""
Context manager that takes a named logger and the logging level
and provides a simple mock-like list of messages received
@@ -510,7 +510,8 @@ def patch_logger(logger_name, log_level):
calls = []
def replacement(msg, *args, **kwargs):
calls.append(msg % args)
call = msg % args
calls.append((call, kwargs) if log_kwargs else call)
logger = logging.getLogger(logger_name)
orig = getattr(logger, log_level)
setattr(logger, log_level, replacement)