Browse Source

Adaption to new logging

master
Dirk Alders 3 years ago
parent
commit
0827a5311f
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      signals.py

+ 8
- 4
signals.py View File

2
 from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed
2
 from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed
3
 from django.dispatch import receiver
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
 @receiver(user_logged_in)
12
 @receiver(user_logged_in)
11
     # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
15
     # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
12
     ip = request.META.get('REMOTE_ADDR')
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
         user=user,
19
         user=user,
16
         ip=ip
20
         ip=ip
17
     ))
21
     ))
21
 def user_logged_out_callback(sender, request, user, **kwargs):
25
 def user_logged_out_callback(sender, request, user, **kwargs):
22
     ip = request.META.get('REMOTE_ADDR')
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
         user=user,
29
         user=user,
26
         ip=ip
30
         ip=ip
27
     ))
31
     ))
31
 def user_login_failed_callback(sender, request, credentials, **kwargs):
35
 def user_login_failed_callback(sender, request, credentials, **kwargs):
32
     ip = request.META.get('REMOTE_ADDR')
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
         user=credentials.get('username'),
39
         user=credentials.get('username'),
36
         ip=ip
40
         ip=ip
37
     ))
41
     ))

Loading…
Cancel
Save