import logging
def foo(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
some_logger = logging.getLogger(__name__)
some_logger.warning('Your log message... IP:' + ip)