/
githubmirror
/
edx-platform
Обзор
Документация
Войти
/
githubmirror
/
edx-platform
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
release-ulmo
openedx/core/lib/log_utils.py
37 строк
1 KB
Usama Sadiq
refactor: Ran pyupgrade on openedx/core
08 апр 2021, 16:34
08 апр 2021, 16:34
8de47ef
Код
Авторство
О чём код?
""" Helper functions for logging. """ import logging log = logging.getLogger(__name__) def audit_log(name, **kwargs): """ DRY helper used to emit an INFO-level log message. Messages logged with this function are used to construct an audit trail. Log messages should be emitted immediately after the event they correspond to has occurred and, if applicable, after the database has been updated. These log messages use a verbose key-value pair syntax to make it easier to extract fields when parsing the application's logs. This function is variadic, accepting a variable number of keyword arguments. Arguments: name (str): The name of the message to log. For example, 'payment_received'. Keyword Arguments: Indefinite. Keyword arguments are strung together as comma-separated key-value pairs ordered alphabetically by key in the resulting log message. Returns: None """ # Joins sorted keyword argument keys and values with an "=", wraps each value # in quotes, and separates each pair with a comma and a space. payload = ', '.join([f'{k}="{v}"' for k, v in sorted(kwargs.items())]) message = f'{name}: {payload}' log.info(message)