Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ Outputs queries as they happen to the terminal, including time taken.
Disable SQL query truncation (used in SQLRealTimeModule) with the ``DEVSERVER_TRUNCATE_SQL`` setting::
DEVSERVER_TRUNCATE_SQL = False
Filter SQL queries with the ``DEVSERVER_FILTER_SQL`` setting::
DEVSERVER_FILTER_SQL = (
re.compile('djkombu_\w+'), # Filter all queries related to Celery
)

devserver.modules.sql.SQLSummaryModule
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
12 changes: 8 additions & 4 deletions devserver/modules/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ def execute(self, sql, params=()):
formatted_sql = sql % (params if isinstance(params, dict) else tuple(params))
if self.logger:
message = formatted_sql
if settings.DEVSERVER_TRUNCATE_SQL:
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
message = sqlparse.format(message, reindent=True, keyword_case='upper')
self.logger.debug(message)
if settings.DEVSERVER_FILTER_SQL:
if any(filter_.search(message) for filter_ in settings.DEVSERVER_FILTER_SQL):
message = None
if message is not None:
if settings.DEVSERVER_TRUNCATE_SQL:
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
message = sqlparse.format(message, reindent=True, keyword_case='upper')
self.logger.debug(message)

start = datetime.now()

Expand Down
1 change: 1 addition & 0 deletions devserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# 'devserver.modules.cache.CacheSummaryModule',
))

DEVSERVER_FILTER_SQL = getattr(settings, 'DEVSERVER_FILTER_SQL', False)
DEVSERVER_TRUNCATE_SQL = getattr(settings, 'DEVSERVER_TRUNCATE_SQL', True)

DEVSERVER_TRUNCATE_AGGREGATES = getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', False))
Expand Down