Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ValUnifer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IPIPAN
ValUnifer
Commits
fdfdb39e
Commit
fdfdb39e
authored
Dec 4, 2023
by
dcz
Browse files
Options
Downloads
Patches
Plain Diff
Log post data
parent
ab2682b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
syntax/middleware.py
+4
-47
4 additions, 47 deletions
syntax/middleware.py
with
4 additions
and
47 deletions
syntax/middleware.py
+
4
−
47
View file @
fdfdb39e
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment