Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion enterprise_access/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ def root(*path_fragments):
PLATFORM_NAME = 'Your Platform Name Here'
# END OPENEDX-SPECIFIC CONFIGURATION

# Override the default logging format string (default defined within utils.py).
LOGGING_FORMAT_STRING = os.environ.get("LOGGING_FORMAT_STRING", None)

# Set up logging for development use (logging to stdout)
LOGGING = get_logger_config(debug=DEBUG)
LOGGING = get_logger_config(debug=DEBUG, format_string=LOGGING_FORMAT_STRING)


"""############################# BEGIN CELERY CONFIG ##################################"""
Expand Down
2 changes: 1 addition & 1 deletion enterprise_access/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

ENABLE_AUTO_AUTH = True

LOGGING = get_logger_config(debug=DEBUG)
LOGGING = get_logger_config(debug=DEBUG, format_string=LOGGING_FORMAT_STRING)
LOG_SQL = False


Expand Down
5 changes: 3 additions & 2 deletions enterprise_access/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

ALLOWED_HOSTS = ['*']

LOGGING = get_logger_config()

# Keep track of the names of settings that represent dicts. Instead of overriding the values in base.py,
# the values read from disk should UPDATE the pre-configured dicts.
DICT_UPDATE_KEYS = ('JWT_AUTH',)
Expand Down Expand Up @@ -50,6 +48,9 @@
vars().update(FILE_STORAGE_BACKEND)
vars().update(MEDIA_STORAGE_BACKEND)

# Must be generated after loading config YAML because LOGGING_FORMAT_STRING might be overridden.
LOGGING = get_logger_config(format_string=LOGGING_FORMAT_STRING)

DB_OVERRIDES = dict(
PASSWORD=environ.get('DB_MIGRATION_PASS', DATABASES['default']['PASSWORD']),
ENGINE=environ.get('DB_MIGRATION_ENGINE', DATABASES['default']['ENGINE']),
Expand Down
31 changes: 23 additions & 8 deletions enterprise_access/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ def get_env_setting(setting):
raise ImproperlyConfigured(error_msg)


def get_logger_config(logging_env="no_env",
debug=False,
service_variant='enterprise-access'):
def get_logger_config(
logging_env: str = "no_env",
debug: bool = False,
service_variant: str = 'enterprise-access',
format_string: str = None,
):
"""
Return the appropriate logging config dictionary. You should assign the
result of this to the LOGGING var in your settings.
Return the appropriate logging config dictionary, to be assigned to the LOGGING var in settings.

Arguments:
logging_env (str): Environment name.
debug (bool): Debug logging enabled.
service_variant (str): Name of the service.
format_string (str): Override format string for your logfiles.

Returns:
dict(string): Returns a dictionary of config values
"""
hostname = platform.node().split(".")[0]
syslog_format = (
Expand All @@ -34,14 +45,18 @@ def get_logger_config(logging_env="no_env",

handlers = ['console']

standard_format = format_string or (
'%(asctime)s %(levelname)s %(process)d [%(name)s] '
'[user %(userid)s] [ip %(remoteip)s] [request_id %(request_id)s] '
'%(filename)s:%(lineno)d - %(message)s'
)

logger_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s %(levelname)s %(process)d '
'[%(name)s] [user %(userid)s] [ip %(remoteip)s] [request_id %(request_id)s] '
'%(filename)s:%(lineno)d - %(message)s',
'format': standard_format,
},
'syslog_format': {'format': syslog_format},
'raw': {'format': '%(message)s'},
Expand Down