-
Notifications
You must be signed in to change notification settings - Fork 48
/
ApiHook.py
executable file
·34 lines (25 loc) · 819 Bytes
/
ApiHook.py
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
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
# @Time : 2019/4/18 3:15 PM
# @Author : ShaHeTop-Almighty-ares
# @Email : [email protected]
# @File : ApiHook.py
# @Software: PyCharm
import time
import shortuuid
from loguru import logger
from flask import request, g
from common.libs.tools import print_logs
def api_before_request():
g.log_uuid = "{}_{}".format(str(int(time.time())), shortuuid.uuid())
logger.info('api_before_request')
logger.info('request log_uuid:{}'.format(g.log_uuid))
print_logs()
if '/api' in request.path:
print('访问api')
return
def api_after_request(response):
logger.info('api_after_request')
logger.info('response log_uuid:{}'.format(g.log_uuid))
logger.info('=== response ===')
response.headers['log_uuid'] = g.log_uuid
return response