Merge pull request #17374 from edx/feanil/hackathon_logging
Make the logging config easier to read.
This commit is contained in:
@@ -256,7 +256,6 @@ WIKI_ENABLED = ENV_TOKENS.get('WIKI_ENABLED', WIKI_ENABLED)
|
||||
|
||||
LOGGING = get_logger_config(LOG_DIR,
|
||||
logging_env=ENV_TOKENS['LOGGING_ENV'],
|
||||
debug=False,
|
||||
service_variant=SERVICE_VARIANT)
|
||||
|
||||
#theming start:
|
||||
|
||||
@@ -213,8 +213,6 @@ if ENV_TOKENS.get('SESSION_COOKIE_NAME', None):
|
||||
# NOTE, there's a bug in Django (http://bugs.python.org/issue18012) which necessitates this being a str()
|
||||
SESSION_COOKIE_NAME = str(ENV_TOKENS.get('SESSION_COOKIE_NAME'))
|
||||
|
||||
LOG_DIR = ENV_TOKENS['LOG_DIR']
|
||||
|
||||
CACHES = ENV_TOKENS['CACHES']
|
||||
# Cache used for location mapping -- called many times with the same key/value
|
||||
# in a given request.
|
||||
@@ -340,12 +338,13 @@ for app in ENV_TOKENS.get('ADDL_INSTALLED_APPS', []):
|
||||
INSTALLED_APPS.append(app)
|
||||
|
||||
WIKI_ENABLED = ENV_TOKENS.get('WIKI_ENABLED', WIKI_ENABLED)
|
||||
|
||||
local_loglevel = ENV_TOKENS.get('LOCAL_LOGLEVEL', 'INFO')
|
||||
LOG_DIR = ENV_TOKENS['LOG_DIR']
|
||||
|
||||
LOGGING = get_logger_config(LOG_DIR,
|
||||
logging_env=ENV_TOKENS['LOGGING_ENV'],
|
||||
local_loglevel=local_loglevel,
|
||||
debug=False,
|
||||
service_variant=SERVICE_VARIANT)
|
||||
|
||||
COURSE_LISTINGS = ENV_TOKENS.get('COURSE_LISTINGS', {})
|
||||
|
||||
@@ -19,9 +19,7 @@ from openedx.core.lib.logsettings import get_logger_config
|
||||
STATIC_GRAB = True
|
||||
|
||||
LOGGING = get_logger_config(ENV_ROOT / "log",
|
||||
logging_env="dev",
|
||||
tracking_filename="tracking.log",
|
||||
debug=False)
|
||||
logging_env="dev")
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
||||
@@ -12,14 +12,8 @@ LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
|
||||
|
||||
def get_logger_config(log_dir,
|
||||
logging_env="no_env",
|
||||
tracking_filename="tracking.log",
|
||||
edx_filename="edx.log",
|
||||
dev_env=False,
|
||||
syslog_addr=None,
|
||||
debug=False,
|
||||
local_loglevel='INFO',
|
||||
console_loglevel=None,
|
||||
service_variant=None):
|
||||
service_variant=""):
|
||||
|
||||
"""
|
||||
|
||||
@@ -28,27 +22,12 @@ def get_logger_config(log_dir,
|
||||
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
|
||||
settings are extended.
|
||||
|
||||
If dev_env is set to true logging will not be done via local rsyslogd,
|
||||
instead, tracking and application logs will be dropped in log_dir.
|
||||
|
||||
"tracking_filename" and "edx_filename" are ignored unless dev_env
|
||||
is set to true since otherwise logging is handled by rsyslogd.
|
||||
|
||||
"""
|
||||
|
||||
# Revert to INFO if an invalid string is passed in
|
||||
if local_loglevel not in LOG_LEVELS:
|
||||
local_loglevel = 'INFO'
|
||||
|
||||
if console_loglevel is None or console_loglevel not in LOG_LEVELS:
|
||||
console_loglevel = 'DEBUG' if debug else 'INFO'
|
||||
|
||||
if service_variant is None:
|
||||
# default to a blank string so that if SERVICE_VARIANT is not
|
||||
# set we will not log to a sub directory
|
||||
service_variant = ''
|
||||
|
||||
hostname = platform.node().split(".")[0]
|
||||
syslog_format = ("[service_variant={service_variant}]"
|
||||
"[%(name)s][env:{logging_env}] %(levelname)s "
|
||||
@@ -57,10 +36,6 @@ def get_logger_config(log_dir,
|
||||
logging_env=logging_env,
|
||||
hostname=hostname)
|
||||
|
||||
handlers = ['console', 'local']
|
||||
if syslog_addr:
|
||||
handlers.append('syslogger-remote')
|
||||
|
||||
logger_config = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
@@ -79,7 +54,7 @@ def get_logger_config(log_dir,
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': console_loglevel,
|
||||
'level': 'INFO',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'standard',
|
||||
'stream': sys.stderr,
|
||||
@@ -89,63 +64,6 @@ def get_logger_config(log_dir,
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'tracking': {
|
||||
'handlers': ['tracking'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
},
|
||||
'': {
|
||||
'handlers': handlers,
|
||||
'level': 'DEBUG',
|
||||
'propagate': False
|
||||
},
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
||||
if syslog_addr:
|
||||
logger_config['handlers'].update({
|
||||
'syslogger-remote': {
|
||||
'level': 'INFO',
|
||||
'class': 'logging.handlers.SysLogHandler',
|
||||
'address': syslog_addr,
|
||||
'formatter': 'syslog_format',
|
||||
},
|
||||
})
|
||||
|
||||
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:
|
||||
# for production environments we will only
|
||||
# log INFO and up
|
||||
logger_config['loggers']['']['level'] = 'INFO'
|
||||
# requests is so loud at INFO (logs every connection) that we force it to warn in production environments
|
||||
logger_config['loggers']['requests.packages.urllib3'] = {'level': 'WARN'}
|
||||
logger_config['handlers'].update({
|
||||
'local': {
|
||||
'level': local_loglevel,
|
||||
'class': 'logging.handlers.SysLogHandler',
|
||||
@@ -160,7 +78,30 @@ def get_logger_config(log_dir,
|
||||
'facility': SysLogHandler.LOG_LOCAL1,
|
||||
'formatter': 'raw',
|
||||
},
|
||||
})
|
||||
},
|
||||
'loggers': {
|
||||
'tracking': {
|
||||
'handlers': ['tracking'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
},
|
||||
'': {
|
||||
'handlers': ['console', 'local'],
|
||||
'level': 'INFO',
|
||||
'propagate': False
|
||||
},
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
# requests is so loud at INFO (logs every connection) that we
|
||||
# force it to warn by default.
|
||||
'requests.packages.urllib3': {
|
||||
'level': 'WARN'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return logger_config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user