blob: c8994ccb039e51fcaff1177ab1483f082585bd65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python
from django.conf import settings
def log_extra_data(additional=None):
'''
Extra data needed by the custom formatter
* If the additional argument is a string or unicode, then its value is
printed in the log.
* If the additional argument is the request, then from the request it
prints the client IP and username if applicable.
'''
extra_data = {
'client_ip': '',
'id_name': '',
'instance_name': settings.INSTANCE_NAME,
}
if not additional:
return extra_data
if type(additional) == str or type(additional) == unicode:
extra_data['id_name'] = additional
else:
request = additional
if request.META:
extra_data['client_ip'] = request.META.get('REMOTE_ADDR', 'None')
try:
if request.user.is_authenticated():
'''
Handle logged in users
'''
extra_data['id_name'] = request.user.name
except AttributeError:
pass
return extra_data
|