|
@@ -2,7 +2,11 @@ import logging
|
2
|
2
|
from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed
|
3
|
3
|
from django.dispatch import receiver
|
4
|
4
|
|
5
|
|
-log = logging.getLogger('AUTH')
|
|
5
|
+try:
|
|
6
|
+ from config import APP_NAME as ROOT_LOGGER_NAME
|
|
7
|
+except ImportError:
|
|
8
|
+ ROOT_LOGGER_NAME = 'root'
|
|
9
|
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
6
|
10
|
|
7
|
11
|
|
8
|
12
|
@receiver(user_logged_in)
|
|
@@ -11,7 +15,7 @@ def user_logged_in_callback(sender, request, user, **kwargs):
|
11
|
15
|
# http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
|
12
|
16
|
ip = request.META.get('REMOTE_ADDR')
|
13
|
17
|
|
14
|
|
- log.info('Accepted password for {user} from {ip}'.format(
|
|
18
|
+ logger.info('Accepted password for {user} from {ip}'.format(
|
15
|
19
|
user=user,
|
16
|
20
|
ip=ip
|
17
|
21
|
))
|
|
@@ -21,7 +25,7 @@ def user_logged_in_callback(sender, request, user, **kwargs):
|
21
|
25
|
def user_logged_out_callback(sender, request, user, **kwargs):
|
22
|
26
|
ip = request.META.get('REMOTE_ADDR')
|
23
|
27
|
|
24
|
|
- log.debug('Disconnected from user {user} {ip}'.format(
|
|
28
|
+ logger.debug('Disconnected from user {user} {ip}'.format(
|
25
|
29
|
user=user,
|
26
|
30
|
ip=ip
|
27
|
31
|
))
|
|
@@ -31,7 +35,7 @@ def user_logged_out_callback(sender, request, user, **kwargs):
|
31
|
35
|
def user_login_failed_callback(sender, request, credentials, **kwargs):
|
32
|
36
|
ip = request.META.get('REMOTE_ADDR')
|
33
|
37
|
|
34
|
|
- log.warning('Failed password for {user} from {ip}'.format(
|
|
38
|
+ logger.warning('Failed password for {user} from {ip}'.format(
|
35
|
39
|
user=credentials.get('username'),
|
36
|
40
|
ip=ip
|
37
|
41
|
))
|