Commit 46508dd8 by David Ormsbee

Merge pull request #620 from MITx/jarv/add-local-logging

Jarv/add local logging
parents dc7304db 99e1dca4
...@@ -48,10 +48,12 @@ for feature, value in ENV_TOKENS.get('MITX_FEATURES', {}).items(): ...@@ -48,10 +48,12 @@ for feature, value in ENV_TOKENS.get('MITX_FEATURES', {}).items():
MITX_FEATURES[feature] = value MITX_FEATURES[feature] = value
WIKI_ENABLED = ENV_TOKENS.get('WIKI_ENABLED', WIKI_ENABLED) WIKI_ENABLED = ENV_TOKENS.get('WIKI_ENABLED', WIKI_ENABLED)
local_loglevel = ENV_TOKENS.get('LOCAL_LOGLEVEL', 'INFO')
LOGGING = get_logger_config(LOG_DIR, LOGGING = get_logger_config(LOG_DIR,
logging_env=ENV_TOKENS['LOGGING_ENV'], logging_env=ENV_TOKENS['LOGGING_ENV'],
syslog_addr=(ENV_TOKENS['SYSLOG_SERVER'], 514), syslog_addr=(ENV_TOKENS['SYSLOG_SERVER'], 514),
local_loglevel=local_loglevel,
debug=False) debug=False)
COURSE_LISTINGS = ENV_TOKENS.get('COURSE_LISTINGS', {}) COURSE_LISTINGS = ENV_TOKENS.get('COURSE_LISTINGS', {})
......
...@@ -13,6 +13,7 @@ from .logsettings import get_logger_config ...@@ -13,6 +13,7 @@ from .logsettings import get_logger_config
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = True TEMPLATE_DEBUG = True
MITX_FEATURES['DISABLE_START_DATES'] = True MITX_FEATURES['DISABLE_START_DATES'] = True
MITX_FEATURES['ENABLE_SQL_TRACKING_LOGS'] = True MITX_FEATURES['ENABLE_SQL_TRACKING_LOGS'] = True
MITX_FEATURES['SUBDOMAIN_COURSE_LISTINGS'] = False # Enable to test subdomains--otherwise, want all courses to show up MITX_FEATURES['SUBDOMAIN_COURSE_LISTINGS'] = False # Enable to test subdomains--otherwise, want all courses to show up
...@@ -24,7 +25,8 @@ WIKI_ENABLED = True ...@@ -24,7 +25,8 @@ WIKI_ENABLED = True
LOGGING = get_logger_config(ENV_ROOT / "log", LOGGING = get_logger_config(ENV_ROOT / "log",
logging_env="dev", logging_env="dev",
tracking_filename="tracking.log", local_loglevel="DEBUG",
dev_env=True,
debug=True) debug=True)
DATABASES = { DATABASES = {
...@@ -57,6 +59,7 @@ CACHES = { ...@@ -57,6 +59,7 @@ CACHES = {
} }
} }
XQUEUE_INTERFACE = { XQUEUE_INTERFACE = {
"url": "https://sandbox-xqueue.edx.org", "url": "https://sandbox-xqueue.edx.org",
"django_auth": { "django_auth": {
...@@ -72,6 +75,7 @@ CACHE_TIMEOUT = 0 ...@@ -72,6 +75,7 @@ CACHE_TIMEOUT = 0
# Dummy secret key for dev # Dummy secret key for dev
SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd' SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
COURSE_LISTINGS = { COURSE_LISTINGS = {
'default': ['BerkeleyX/CS169.1x/2012_Fall', 'default': ['BerkeleyX/CS169.1x/2012_Fall',
'BerkeleyX/CS188.1x/2012_Fall', 'BerkeleyX/CS188.1x/2012_Fall',
...@@ -87,6 +91,7 @@ COURSE_LISTINGS = { ...@@ -87,6 +91,7 @@ COURSE_LISTINGS = {
'sjsu': ['MITx/6.002x-EE98/2012_Fall_SJSU'], 'sjsu': ['MITx/6.002x-EE98/2012_Fall_SJSU'],
} }
SUBDOMAIN_BRANDING = { SUBDOMAIN_BRANDING = {
'sjsu': 'MITx', 'sjsu': 'MITx',
'mit': 'MITx', 'mit': 'MITx',
...@@ -96,6 +101,8 @@ SUBDOMAIN_BRANDING = { ...@@ -96,6 +101,8 @@ SUBDOMAIN_BRANDING = {
COMMENTS_SERVICE_KEY = "PUT_YOUR_API_KEY_HERE" COMMENTS_SERVICE_KEY = "PUT_YOUR_API_KEY_HERE"
################################ LMS Migration ################################# ################################ LMS Migration #################################
MITX_FEATURES['ENABLE_LMS_MIGRATION'] = True MITX_FEATURES['ENABLE_LMS_MIGRATION'] = True
MITX_FEATURES['ACCESS_REQUIRE_STAFF_FOR_COURSE'] = False # require that user be in the staff_* group to be able to enroll MITX_FEATURES['ACCESS_REQUIRE_STAFF_FOR_COURSE'] = False # require that user be in the staff_* group to be able to enroll
...@@ -121,6 +128,7 @@ OPENID_USE_AS_ADMIN_LOGIN = False ...@@ -121,6 +128,7 @@ OPENID_USE_AS_ADMIN_LOGIN = False
OPENID_PROVIDER_TRUSTED_ROOTS = ['*'] OPENID_PROVIDER_TRUSTED_ROOTS = ['*']
################################ MIT Certificates SSL Auth ################################# ################################ MIT Certificates SSL Auth #################################
MITX_FEATURES['AUTH_USE_MIT_CERTIFICATES'] = True MITX_FEATURES['AUTH_USE_MIT_CERTIFICATES'] = True
################################ DEBUG TOOLBAR ################################# ################################ DEBUG TOOLBAR #################################
......
import os import os
import os.path
import platform import platform
import sys import sys
from logging.handlers import SysLogHandler
def get_logger_config(log_dir, def get_logger_config(log_dir,
logging_env="no_env", logging_env="no_env",
tracking_filename=None, tracking_filename="tracking.log",
edx_filename="edx.log",
dev_env=False,
syslog_addr=None, syslog_addr=None,
debug=False): debug=False,
"""Return the appropriate logging config dictionary. You should assign the local_loglevel='INFO'):
"""
Return the appropriate logging config dictionary. You should assign the
result of this to the LOGGING var in your settings. The reason it's done result of this to the LOGGING var in your settings. The reason it's done
this way instead of registering directly is because I didn't want to worry this way instead of registering directly is because I didn't want to worry
about resetting the logging state if this is called multiple times when about resetting the logging state if this is called multiple times when
settings are extended.""" settings are extended.
# If we're given an explicit place to put tracking logs, we do that (say for If dev_env is set to true logging will not be done via local rsyslogd,
# debugging). However, logging is not safe for multiple processes hitting instead, tracking and application logs will be dropped in log_dir.
# the same file. So if it's left blank, we dynamically create the filename
# based on the PID of this worker process. "tracking_filename" and "edx_filename" are ignored unless dev_env
if tracking_filename: is set to true since otherwise logging is handled by rsyslogd.
tracking_file_loc = os.path.join(log_dir, tracking_filename)
else: """
pid = os.getpid() # So we can log which process is creating the log
tracking_file_loc = os.path.join(log_dir, "tracking_{0}.log".format(pid)) # Revert to INFO if an invalid string is passed in
if local_loglevel not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
local_loglevel = 'INFO'
hostname = platform.node().split(".")[0] hostname = platform.node().split(".")[0]
syslog_format = ("[%(name)s][env:{logging_env}] %(levelname)s [{hostname} " + syslog_format = ("[%(name)s][env:{logging_env}] %(levelname)s "
" %(process)d] [%(filename)s:%(lineno)d] - %(message)s").format( "[{hostname} %(process)d] [%(filename)s:%(lineno)d] "
"- %(message)s").format(
logging_env=logging_env, hostname=hostname) logging_env=logging_env, hostname=hostname)
handlers = ['console'] if debug else ['console', 'syslogger', 'newrelic'] handlers = ['console', 'local'] if debug else ['console',
'syslogger-remote', 'local', 'newrelic']
return { logger_config = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
'formatters' : { 'formatters': {
'standard' : { 'standard': {
'format' : '%(asctime)s %(levelname)s %(process)d [%(name)s] %(filename)s:%(lineno)d - %(message)s', 'format': '%(asctime)s %(levelname)s %(process)d '
'[%(name)s] %(filename)s:%(lineno)d - %(message)s',
}, },
'syslog_format' : { 'format' : syslog_format }, 'syslog_format': {'format': syslog_format},
'raw' : { 'format' : '%(message)s' }, 'raw': {'format': '%(message)s'},
}, },
'handlers' : { 'handlers': {
'console' : { 'console': {
'level' : 'DEBUG' if debug else 'INFO', 'level': 'DEBUG' if debug else 'INFO',
'class' : 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter' : 'standard', 'formatter': 'standard',
'stream' : sys.stdout, 'stream': sys.stdout,
}, },
'syslogger' : { 'syslogger-remote': {
'level' : 'INFO', 'level': 'INFO',
'class' : 'logging.handlers.SysLogHandler', 'class': 'logging.handlers.SysLogHandler',
'address' : syslog_addr, 'address': syslog_addr,
'formatter' : 'syslog_format', 'formatter': 'syslog_format',
}, },
'tracking' : { 'newrelic': {
'level' : 'DEBUG',
'class' : 'logging.handlers.WatchedFileHandler',
'filename' : tracking_file_loc,
'formatter' : 'raw',
},
'newrelic' : {
'level': 'ERROR', 'level': 'ERROR',
'class': 'newrelic_logging.NewRelicHandler', 'class': 'newrelic_logging.NewRelicHandler',
'formatter': 'raw', 'formatter': 'raw',
} }
}, },
'loggers' : { 'loggers': {
'django' : { 'django': {
'handlers' : handlers, 'handlers': handlers,
'propagate' : True, 'propagate': True,
'level' : 'INFO' 'level': 'INFO'
}, },
'tracking' : { 'tracking': {
'handlers' : ['tracking'], 'handlers': ['tracking'],
'level' : 'DEBUG', 'level': 'DEBUG',
'propagate' : False, 'propagate': False,
}, },
'' : { '': {
'handlers' : handlers, 'handlers': handlers,
'level' : 'DEBUG', 'level': 'DEBUG',
'propagate' : False 'propagate': False
}, },
'mitx' : { 'mitx': {
'handlers' : handlers, 'handlers': handlers,
'level' : 'DEBUG', 'level': 'DEBUG',
'propagate' : False 'propagate': False
}, },
'keyedcache' : { 'keyedcache': {
'handlers' : handlers, 'handlers': handlers,
'level' : 'DEBUG', 'level': 'DEBUG',
'propagate' : False 'propagate': False
}, },
} }
} }
if dev_env:
tracking_file_loc = os.path.join(log_dir, tracking_filename)
edx_file_loc = os.path.join(log_dir, edx_filename)
logger_config['handlers'].update({
'local': {
'class': 'logging.handlers.RotatingFileHandler',
'level': local_loglevel,
'formatter': 'standard',
'filename': edx_file_loc,
'maxBytes': 1024 * 1024 * 2,
'backupCount': 5,
},
'tracking': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': tracking_file_loc,
'formatter': 'raw',
'maxBytes': 1024 * 1024 * 2,
'backupCount': 5,
},
})
else:
logger_config['handlers'].update({
'local': {
'level': local_loglevel,
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
'formatter': 'syslog_format',
'facility': SysLogHandler.LOG_LOCAL0,
},
'tracking': {
'level': 'DEBUG',
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
'facility': SysLogHandler.LOG_LOCAL1,
'formatter': 'raw',
},
})
return logger_config
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment