kadenios/shared/mixins.py

24 lines
732 B
Python
Raw Permalink Normal View History

from .models import Event
# #############################################################################
# Fonctions pour la journalisation
# #############################################################################
class LogMixin:
"""Utility to log events related to the current user"""
def _log(self, message, level, data={}):
Event.objects.create(
message=message, level=level, user=self.request.user, data=data
)
def log_info(self, message, data={}):
self._log(message, "info", data=data)
def log_warn(self, message, data={}):
self._log(message, "warn", data=data)
def log_error(self, message, data={}):
self._log(message, "error", data=data)