Skip to content
Snippets Groups Projects
Commit fdfdb39e authored by dcz's avatar dcz
Browse files

Log post data

parent ab2682b4
No related branches found
No related tags found
No related merge requests found
......@@ -10,62 +10,19 @@ from django.utils.deprecation import MiddlewareMixin
# from sentry_sdk import capture_exception
# def get_client_ip(request):
# """
# get client ip address
#
# used in:
# - apps/models_helper/visitor.py
# """
# ip_address = request.META.get('HTTP_X_FORWARDED_FOR', None)
# if ip_address:
# ip_address = ip_address.split(', ')[0]
# else:
# ip_address = request.META.get('REMOTE_ADDR', '')
# return ip_address
class SessionLogMiddleware(MiddlewareMixin):
"""
this middleware to create a log
by current user
"""
def process_exception(self, request, exception):
# print(type(exception), exception) # just for debug
status_code = 404 if isinstance(exception, Http404) else 500
try:
# try:
# request_data = json.loads(str(request.POST))
# except RawPostDataException:
# response_data = "RawPostDataException: You cannot access body after reading from request's data stream"
# except Exception:
# try:
# request_data = str(request.body)
# except Exception:
# pass
print("user: id={}, name={}".format(request.user.id, request.user.username))
print("request_data: {}".format(request.POST))
print("exception: {}".format(exception))
# print("stck: {}".format(traceback.format_exc(exception)))
# self.save_mongodb_logging(request,
# exception=exception,
# status_code=status_code)
print("Exception, user-id={}, user-name={}, path={}, post={}, get={}".format(request.user.id, request.user.username, request.path, request.POST, request.GET))
except Exception as error:
# error = traceback.format_exc()
# capture_exception(error)
print(error)
return # no return anything
# def process_response(self, request, response):
# if not response.status_code >= 400:
# try:
# response_data = {'request': request,
# 'response': response,
# 'status_code': response.status_code}
# self.save_mongodb_logging(**response_data)
# except Exception:
# pass
# return response
def process_response(self, request, response):
print("user: id={}, name={}, path={}, post={}, get={}".format(request.user.id, request.user.username, request.path, request.POST, request.GET))
return response
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment