Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Gunicorn Logging Configuration for Datadog Compatibility #442

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 7 additions & 41 deletions notesserver/settings/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def build_logging_config():
"""
Return the appropriate logging config dictionary. You should assign the
result of this to the LOGGING var in your settings.
If dev_env is set to true logging will not be done via local rsyslogd,
instead, application logs will be dropped in log_dir.
"edx_filename" is 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

Expand All @@ -37,21 +33,19 @@ def build_logging_config():
syslog_format = (
"[service_variant={service_variant}]"
"[%(name)s][env:{logging_env}] %(levelname)s "
"[{hostname} %(process)d] [%(filename)s:%(lineno)d] "
"[{hostname} %(process)d] [%(filename)s:%(lineno)d] "
"- %(message)s"
).format(service_variant=service_variant, logging_env=logging_env, hostname=hostname)

if debug:
handlers = ['console']
else:
handlers = ['local']
handlers = ['console']

logger_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s %(levelname)s %(process)d ' '[%(name)s] %(filename)s:%(lineno)d - %(message)s',
'format': '%(asctime)s,%(msecs)03d %(levelname)s [%(name)s] [%(process)d] - %(message)s',
'datefmt': '%Y-%m-%dT%H:%M:%S',
},
'syslog_format': {'format': syslog_format},
'raw': {'format': '%(message)s'},
Expand All @@ -65,38 +59,10 @@ def build_logging_config():
},
},
'loggers': {
'django': {'handlers': handlers, 'propagate': True, 'level': 'INFO'},
"elasticsearch.trace": {'handlers': handlers, 'level': 'WARNING', 'propagate': False},
'': {'handlers': handlers, 'level': 'DEBUG', 'propagate': False},
'django': {'handlers': handlers, 'propagate': True, 'level': 'INFO', 'formatter': 'standard'},
"elasticsearch.trace": {'handlers': handlers, 'level': 'WARNING', 'propagate': False, 'formatter': 'standard'},
'': {'handlers': handlers, 'level': 'DEBUG', 'propagate': False, 'formatter': 'standard'},
},
}

if dev_env:
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,
}
}
)
else:
logger_config['handlers'].update(
{
'local': {
'level': local_loglevel,
'class': 'logging.handlers.SysLogHandler',
# Use a different address for Mac OS X
'address': '/var/run/syslog' if sys.platform == "darwin" else '/dev/log',
'formatter': 'syslog_format',
'facility': SysLogHandler.LOG_LOCAL0,
}
}
)

return logger_config