import logging logger logging getLogger logger setLevel logging INFO f

 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
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = '%(asctime)s %(filename)s: %(message)s'
logging.basicConfig(filename='logging.log', format=formatter,
datefmt='%d-%m-%Y %H:%M:%S')
class LoggingDataMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
name_method = request.method
full_path = request.environ['PATH_INFO']
ip = request.META.get('REMOTE_ADDR')
logging.info(f'{ip} - {name_method} - {full_path}')
response = self.get_response(request)
return response