Skip to content

Query log

log_query(query, source) ΒΆ

Call this to log a query dict to the query log file (if the config permits it). The query is simply json dumped. If query logging is disabled then nothing happens.

Parameters:

Name Type Description Default
query

the query dict

required
source

the source of the query (e.g. multisearch or basicsearch)

required
Source code in ckanext/versioned_datastore/lib/query/query_log.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def log_query(query, source):
    """
    Call this to log a query dict to the query log file (if the config permits it). The
    query is simply json dumped. If query logging is disabled then nothing happens.

    :param query: the query dict
    :param source: the source of the query (e.g. multisearch or basicsearch)
    """
    if is_enabled:
        # use suppress just to make sure nothing explodes whilst logging
        with suppress(Exception):
            logger.info(
                f'{source}: {json.dumps(query, sort_keys=True, ensure_ascii=False)}'
            )