Skip to content

Commit f641d3d

Browse files
committed
Add debug logging for Queries
Add a configurable logger for logging Servershell and API queries to a dedicated file.
1 parent 10ea615 commit f641d3d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

serveradmin/serverdb/query_executer.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""Serveradmin - Query Executer
22
3-
Copyright (c) 2019 InnoGames GmbH
3+
Copyright (c) 2025 InnoGames GmbH
44
"""
55

6+
import logging
7+
import time
8+
69
from django.core.exceptions import ObjectDoesNotExist, ValidationError
710
from django.db import DataError, connection, transaction
811

912
from adminapi.filters import Any
13+
from adminapi.parse import build_query
1014
from serveradmin.serverdb.models import Attribute, ServertypeAttribute, Server
1115
from serveradmin.serverdb.query_builder import get_server_query
1216
from serveradmin.serverdb.query_materializer import QueryMaterializer
@@ -15,6 +19,8 @@
1519
def execute_query(filters, restrict, order_by):
1620
"""The main function to execute queries"""
1721

22+
start = time.time()
23+
1824
# We need the restrict argument in slightly different structure.
1925
if restrict is None:
2026
joins = None
@@ -98,7 +104,12 @@ def cast(join):
98104
# materializer module for its details. The functions on this module
99105
# continues with the filtering step.
100106
servers = _get_servers(filters, attribute_lookup, related_vias)
101-
return list(QueryMaterializer(servers, *materializer_args))
107+
result = list(QueryMaterializer(servers, *materializer_args))
108+
109+
duration = time.time() - start
110+
logging.getLogger('queries').debug(f"{build_query(filters)};{duration:.3f}s;{len(result)}")
111+
112+
return result
102113

103114

104115
def _get_joins(restrict):

0 commit comments

Comments
 (0)