Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

use python logging to log user ips+time in a file whenever a request comes to the server, this should be done in a custom middleware.

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #logging #log #user #file #request #custom
ADD COMMENT
Topic
Name
2+4 =