优化日志格式bug

pull/91/MERGE
李强 2023-04-04 00:29:50 +08:00
parent d4b49cecf5
commit ec4e3d8a37
2 changed files with 12 additions and 9 deletions

View File

@ -77,9 +77,10 @@ class DeptInitSerializer(CustomModelSerializer):
menu_data['parent'] = instance.id
filter_data = {
"name": menu_data['name'],
"parent": menu_data['parent'],
"key": menu_data['key']
"parent": menu_data['parent']
}
if 'key' in menu_data:
filter_data['key'] = menu_data['key']
instance_obj = Dept.objects.filter(**filter_data).first()
if instance_obj and not self.initial_data.get('reset'):
continue
@ -147,12 +148,12 @@ class DeptViewSet(CustomModelViewSet):
parent = params.get('parent', None)
if params:
if parent:
queryset = self.queryset.filter(status=True, parent=parent)
queryset = self.queryset.filter(parent=parent)
else:
queryset = self.queryset.filter(status=True)
queryset = self.queryset.filter(parent__isnull=True)
else:
queryset = self.queryset.filter(status=True, parent__isnull=True)
queryset = self.filter_queryset(queryset)
queryset = self.queryset.filter(parent__isnull=True)
queryset = self.filter_queryset(queryset.order_by('sort', 'create_datetime'))
serializer = DeptSerializer(queryset, many=True, request=request)
data = serializer.data
return SuccessResponse(data=data)

View File

@ -24,7 +24,7 @@ class InterceptTimedRotatingFileHandler(RotatingFileHandler):
filename = os.path.abspath(filename)
# 定义默认格式
if not format:
format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <green>{extra[client_addr]:^18}</green> | <level>{level: <8}</level>| <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <green>{extra[client_addr]:^18}</green> | <level>{level: <8}</level>| <cyan>{message}</cyan>"
when = when.lower()
# 2.🎖️需要本地用不同的文件名做为不同日志的筛选器
logger.configure(
@ -116,10 +116,12 @@ class InterceptTimedRotatingFileHandler(RotatingFileHandler):
elif isinstance(record.args, tuple) and len(record.args) > 0:
if ":" in str(record.args[0]):
record_client = record.args[0]
msg = f"{msg.split('-')[1].strip(' ')}"
if msg.split("-") and len(msg.split("-")) == 2:
msg = f"{msg.split('-')[1].strip(' ')}"
elif isinstance(record.args[0], tuple) and len(record.args[0]) == 2:
record_client = f"{record.args[0][0]}:{record.args[0][1]}"
msg = f"{msg.split('-')[1].strip(' ')}"
if msg.split("-") and len(msg.split("-")) == 2:
msg = f"{msg.split('-')[1].strip(' ')}"
client = record_client or (details and details.get('client'))
if client:
bind["client_addr"] = client