Set up proper logging

This commit is contained in:
Tanner Collin 2020-03-08 00:36:16 +00:00
parent 8ff4997810
commit 464db5cf28
2 changed files with 36 additions and 17 deletions

View File

@ -0,0 +1,10 @@
import logging
class IgnoreStats(logging.Filter):
def filter(self, record):
if 'GET /stats/' in record.msg:
return False
elif 'POST /stats/' in record.msg:
return False
else:
return True

View File

@ -11,7 +11,9 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
""" """
import os import os
import logging import logging.config
logger = logging.getLogger(__name__)
from . import secrets from . import secrets
@ -206,22 +208,24 @@ REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': DEFAULT_AUTHENTICATION_CLASSES, 'DEFAULT_AUTHENTICATION_CLASSES': DEFAULT_AUTHENTICATION_CLASSES,
} }
#DEFAULT_LOGGING = None
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False,
'formatters': { 'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'medium': { 'medium': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s' 'format': '[%(asctime)s] [%(process)d] [%(levelname)7s] %(message)s'
}, },
'simple': { },
'format': '%(levelname)s %(message)s' 'filters': {
'ignore_stats': {
'()': 'apiserver.filters.IgnoreStats',
}, },
}, },
'handlers': { 'handlers': {
'console': { 'console': {
'level': 'INFO', 'level': 'DEBUG',
'filters': ['ignore_stats'],
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': 'medium' 'formatter': 'medium'
}, },
@ -229,21 +233,21 @@ LOGGING = {
'loggers': { 'loggers': {
'gunicorn': { 'gunicorn': {
'handlers': ['console'], 'handlers': ['console'],
'level': 'ERROR', 'level': 'DEBUG',
'propagate': True, 'propagate': False,
},
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
}, },
'': { '': {
'handlers': ['console'], 'handlers': ['console'],
'level': 'INFO', 'level': 'DEBUG',
'propagate': True, 'propagate': True,
}, },
},
'root': {
'level': 'INFO',
'handlers': ['console'],
},
} }
} logging.config.dictConfig(LOGGING)
SITE_ID = 1 SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_REQUIRED = True
@ -253,3 +257,8 @@ ACCOUNT_AUTHENTICATION_METHOD = 'username'
OLD_PASSWORD_FIELD_ENABLED = True OLD_PASSWORD_FIELD_ENABLED = True
LOGOUT_ON_PASSWORD_CHANGE = False LOGOUT_ON_PASSWORD_CHANGE = False
ACCOUNT_PRESERVE_USERNAME_CASING = False ACCOUNT_PRESERVE_USERNAME_CASING = False
logger.info('Test logging for each thread')
#import logging_tree
#logging_tree.printout()