mirror of https://github.com/jumpserver/jumpserver
fix(logger): 把 drf 异常放到单独的日志文件中
parent
5e779e6542
commit
f6031d6f5d
|
@ -6,9 +6,10 @@ from rest_framework.views import set_rollback
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from common.exceptions import JMSObjectDoesNotExist
|
from common.exceptions import JMSObjectDoesNotExist
|
||||||
from common.utils import get_logger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = getLogger('drf_exception')
|
||||||
|
unexpected_exception_logger = getLogger('unexpected_exception')
|
||||||
|
|
||||||
|
|
||||||
def extract_object_name(exc, index=0):
|
def extract_object_name(exc, index=0):
|
||||||
|
@ -45,5 +46,7 @@ def common_exception_handler(exc, context):
|
||||||
|
|
||||||
set_rollback()
|
set_rollback()
|
||||||
return Response(data, status=exc.status_code, headers=headers)
|
return Response(data, status=exc.status_code, headers=headers)
|
||||||
|
else:
|
||||||
|
unexpected_exception_logger.exception('')
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -11,8 +11,6 @@ import time
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from .timezone import dt_formater
|
|
||||||
|
|
||||||
|
|
||||||
UUID_PATTERN = re.compile(r'\w{8}(-\w{4}){3}-\w{12}')
|
UUID_PATTERN = re.compile(r'\w{8}(-\w{4}){3}-\w{12}')
|
||||||
ipip_db = None
|
ipip_db = None
|
||||||
|
|
|
@ -5,6 +5,8 @@ from ..const import PROJECT_DIR, CONFIG
|
||||||
|
|
||||||
LOG_DIR = os.path.join(PROJECT_DIR, 'logs')
|
LOG_DIR = os.path.join(PROJECT_DIR, 'logs')
|
||||||
JUMPSERVER_LOG_FILE = os.path.join(LOG_DIR, 'jumpserver.log')
|
JUMPSERVER_LOG_FILE = os.path.join(LOG_DIR, 'jumpserver.log')
|
||||||
|
DRF_EXCEPTION_LOG_FILE = os.path.join(LOG_DIR, 'drf_exception.log')
|
||||||
|
UNEXPECTED_EXCEPTION_LOG_FILE = os.path.join(LOG_DIR, 'unexpected_exception.log')
|
||||||
ANSIBLE_LOG_FILE = os.path.join(LOG_DIR, 'ansible.log')
|
ANSIBLE_LOG_FILE = os.path.join(LOG_DIR, 'ansible.log')
|
||||||
GUNICORN_LOG_FILE = os.path.join(LOG_DIR, 'gunicorn.log')
|
GUNICORN_LOG_FILE = os.path.join(LOG_DIR, 'gunicorn.log')
|
||||||
LOG_LEVEL = CONFIG.LOG_LEVEL
|
LOG_LEVEL = CONFIG.LOG_LEVEL
|
||||||
|
@ -20,6 +22,10 @@ LOGGING = {
|
||||||
'datefmt': '%Y-%m-%d %H:%M:%S',
|
'datefmt': '%Y-%m-%d %H:%M:%S',
|
||||||
'format': '%(asctime)s [%(module)s %(levelname)s] %(message)s',
|
'format': '%(asctime)s [%(module)s %(levelname)s] %(message)s',
|
||||||
},
|
},
|
||||||
|
'exception': {
|
||||||
|
'datefmt': '%Y-%m-%d %H:%M:%S',
|
||||||
|
'format': '\n%(asctime)s [%(levelname)s] %(message)s',
|
||||||
|
},
|
||||||
'simple': {
|
'simple': {
|
||||||
'format': '%(levelname)s %(message)s'
|
'format': '%(levelname)s %(message)s'
|
||||||
},
|
},
|
||||||
|
@ -58,6 +64,24 @@ LOGGING = {
|
||||||
'backupCount': 7,
|
'backupCount': 7,
|
||||||
'filename': ANSIBLE_LOG_FILE,
|
'filename': ANSIBLE_LOG_FILE,
|
||||||
},
|
},
|
||||||
|
'drf_exception': {
|
||||||
|
'encoding': 'utf8',
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'formatter': 'exception',
|
||||||
|
'maxBytes': 1024 * 1024 * 100,
|
||||||
|
'backupCount': 7,
|
||||||
|
'filename': DRF_EXCEPTION_LOG_FILE,
|
||||||
|
},
|
||||||
|
'unexpected_exception': {
|
||||||
|
'encoding': 'utf8',
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'formatter': 'exception',
|
||||||
|
'maxBytes': 1024 * 1024 * 100,
|
||||||
|
'backupCount': 7,
|
||||||
|
'filename': UNEXPECTED_EXCEPTION_LOG_FILE,
|
||||||
|
},
|
||||||
'syslog': {
|
'syslog': {
|
||||||
'level': 'INFO',
|
'level': 'INFO',
|
||||||
'class': 'logging.NullHandler',
|
'class': 'logging.NullHandler',
|
||||||
|
@ -84,6 +108,14 @@ LOGGING = {
|
||||||
'handlers': ['console', 'file'],
|
'handlers': ['console', 'file'],
|
||||||
'level': LOG_LEVEL,
|
'level': LOG_LEVEL,
|
||||||
},
|
},
|
||||||
|
'drf_exception': {
|
||||||
|
'handlers': ['console', 'drf_exception'],
|
||||||
|
'level': LOG_LEVEL,
|
||||||
|
},
|
||||||
|
'unexpected_exception': {
|
||||||
|
'handlers': ['unexpected_exception'],
|
||||||
|
'level': LOG_LEVEL,
|
||||||
|
},
|
||||||
'ops.ansible_api': {
|
'ops.ansible_api': {
|
||||||
'handlers': ['console', 'ansible_logs'],
|
'handlers': ['console', 'ansible_logs'],
|
||||||
'level': LOG_LEVEL,
|
'level': LOG_LEVEL,
|
||||||
|
|
Loading…
Reference in New Issue