Signals

register_custom_log

This signal allows you to log custom events within the application backend. An example of its use can be seen in the login_view.py view of the accounts app to record when a user has logged in correctly:

# signals.py file

from django.dispatch import Signal

from . import models

register_event = Signal()


def register_custom_log(sender, activity_text, user, extra_params=None, **kwargs):
    models.AuditEventLog.create_register(activity_text, extra_params, user)
# custom implementation file

from apps.audit import signals as audit_signals

audit_signals.register_event.send(
    sender=None, # or User instance
    activity_text="Failed login attempt",
    user=None, # or User instance
    extra_params={
        "user_agent": get_device(request),
        "ip": get_ip(request),
        "param": custon_value
    },
)