-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mitodl/edx-logging
Adding initial pass of extending logging configuration for edx-platform
- Loading branch information
Showing
9 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
python_library( | ||
name="edx_logging", | ||
dependencies=[ | ||
"src/ol_openedx_logging/settings", | ||
"//:python-json-logger", | ||
] | ||
) | ||
|
||
python_distribution( | ||
name="logging_package", | ||
dependencies=[":edx_logging"], | ||
provides=setup_py( | ||
name="ol-openedx-logging", | ||
version="0.1.0", | ||
description="An Open edX plugin to customize the logging configuration used by the edx-platform application", | ||
entry_points={ | ||
"lms.djangoapp": ["ol_openedx_logging = ol_openedx_logging.app:EdxLoggingLMS"], | ||
"cms.djangoapp": ["ol_openedx_logging = ol_openedx_logging.app:EdxLoggingCMS"] | ||
} | ||
), | ||
setup_py_commands=["sdist", "bdist_wheel"] | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class EdxLoggingLMS(AppConfig): | ||
name = "ol_openedx_logging" | ||
verbose_name = "Log customization support for Open edX platform" | ||
plugin_app = { | ||
"settings_config": { | ||
"lms.djangoapp": {"production": {"relative_path": "settings.production"}} | ||
} | ||
} | ||
|
||
|
||
class EdxLoggingCMS(AppConfig): | ||
name = "ol_openedx_logging" | ||
verbose_name = "Log customization support for Open edX platform" | ||
plugin_app = { | ||
"settings_config": { | ||
"cms.djangoapp": {"production": {"relative_path": "settings.production"}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python_library() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Any, Dict | ||
|
||
MEGABYTE = 1024 * 1024 | ||
|
||
|
||
def _load_env_tokens(edx_settings, default_settings: Dict[str, Any]) -> Dict[str, Any]: | ||
configured_tokens = getattr(edx_settings, "ENV_TOKENS", {}) | ||
default_settings.update(configured_tokens) | ||
return default_settings | ||
|
||
|
||
def plugin_settings(edx_settings): | ||
env_tokens = _load_env_tokens( | ||
edx_settings, | ||
{ | ||
"EDXAPP_LOG_LEVEL": "INFO", | ||
"EDXAPP_LOG_FILE_PATH": "/var/log/edxapp/app.log", | ||
"EDXAPP_LOG_FILE_MAX_MEGABYTES": 10, | ||
}, | ||
) | ||
edx_logging = getattr(edx_settings, "LOGGING", {}) | ||
edx_log_level = env_tokens["EDXAPP_LOG_LEVEL"] | ||
|
||
edx_logging["formatters"]["json_format"] = { | ||
"()": "pythonjsonlogger.jsonlogger.JsonFormatter", | ||
"timestamp": True, | ||
"reserved_attrs": [], # Add all log attributes to JSON object | ||
} | ||
|
||
edx_logging["handlers"]["file"] = { | ||
"level": edx_log_level, | ||
"class": "logging.handlers.RotatingFileHandler", | ||
"filename": env_tokens["EDXAPP_LOG_FILE_PATH"], | ||
"formatter": "json_format", | ||
"backupCount": 3, | ||
"mode": "a", | ||
"maxBytes": MEGABYTE * env_tokens["EDXAPP_LOG_FILE_MAX_MEGABYTES"], | ||
} | ||
|
||
edx_logging["loggers"][""] = { | ||
"handlers": ["console", "local", "file"], | ||
"level": edx_log_level, | ||
"propagate": False, | ||
} | ||
|
||
edx_settings.LOGGING = edx_logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters