Skip to content

Commit

Permalink
增加全局异常捕获,方便定位问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo authored and lihuanhuan committed Apr 11, 2018
1 parent 00f98b3 commit 6e758b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions archer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'sql.check_login_middleware.CheckLoginMiddleware',
'sql.exception_logging_middleware.ExceptionLoggingMiddleware',
)

ROOT_URLCONF = 'archer.urls'
Expand Down Expand Up @@ -208,6 +209,16 @@
'handlers': ['default'],
'level': 'DEBUG',
},
'django.db': { # 打印SQL语句到console,方便开发
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django.request': { # 打印SQL语句到console,方便开发
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django_auth_ldap': { # django_auth_ldap模块相关日志打印到console
'handlers': ['ldap'],
'level': 'DEBUG',
Expand Down
10 changes: 10 additions & 0 deletions sql/exception_logging_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: UTF-8 -*-
import logging

logger = logging.getLogger('default')


class ExceptionLoggingMiddleware(object):
def process_exception(self, request, exception):
import traceback
logger.error(traceback.format_exc())

0 comments on commit 6e758b0

Please sign in to comment.