How can I log both successful and failed login and logout attempts in Django?
You could hook up to the provided signals: django.contrib.auth.signals Recording to log import logging from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed from django.dispatch import receiver log = logging.getLogger(__name__) @receiver(user_logged_in) def user_logged_in_callback(sender, request, user, **kwargs): # to cover more complex cases: # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django ip = request.META.get(‘REMOTE_ADDR’) log.debug(‘login user: {user} via ip: {ip}’.format( user=user, ip=ip )) @receiver(user_logged_out) def … Read more