diff --git a/conf/settings.py b/conf/settings.py index 5d77582..a00168f 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -15,12 +15,6 @@ from django_yunohost_integration.base_settings import * # noqa from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret -# Set via config_panel.toml -DEBUG_ENABLED = '__DEBUG_ENABLED__' -DEBUG = bool(int(DEBUG_ENABLED)) - -# ----------------------------------------------------------------------------- - FINALPATH = __Path('__FINALPATH__') # /opt/yunohost/$app assert FINALPATH.is_dir(), f'Directory not exists: {FINALPATH}' @@ -33,6 +27,23 @@ assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}' PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH PATH_URL = PATH_URL.strip('/') +# ----------------------------------------------------------------------------- +# config_panel.toml settings: + +DEBUG_ENABLED = '__DEBUG_ENABLED__' +LOG_LEVEL = '__LOG_LEVEL__' + +# ----------------------------------------------------------------------------- + +DEBUG = bool(int(DEBUG_ENABLED)) +assert LOG_LEVEL in ( + 'DEBUG', + 'INFO', + 'WARNING', + 'ERROR', + 'CRITICAL', +), f'Invalid LOG_LEVEL: {LOG_LEVEL!r}' + # ----------------------------------------------------------------------------- # Function that will be called to finalize a user profile: @@ -111,6 +122,7 @@ else: STATIC_ROOT = str(PUBLIC_PATH / 'static') MEDIA_ROOT = str(PUBLIC_PATH / 'media') + # ----------------------------------------------------------------------------- LOGGING = { @@ -137,17 +149,17 @@ LOGGING = { }, }, 'loggers': { - '': {'handlers': ['log_file', 'mail_admins'], 'level': 'INFO', 'propagate': False}, - 'django': {'handlers': ['log_file', 'mail_admins'], 'level': 'INFO', 'propagate': False}, - 'axes': {'handlers': ['log_file', 'mail_admins'], 'level': 'WARNING', 'propagate': False}, + '': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False}, + 'django': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False}, + 'axes': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False}, 'django_tools': { 'handlers': ['log_file', 'mail_admins'], - 'level': 'INFO', + 'level': LOG_LEVEL, 'propagate': False, }, 'django_yunohost_integration': { 'handlers': ['log_file', 'mail_admins'], - 'level': 'INFO', + 'level': LOG_LEVEL, 'propagate': False, }, }, diff --git a/config_panel.toml b/config_panel.toml index c7144fc..1838c99 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -14,3 +14,10 @@ services = ["__APP__"] no = "0" help = "Should be never enabled in production!" bind = "debug_enabled:__FINALPATH__/settings.py" + + [main.config.log_level] + type = "string" + ask = "Log Level" + choices = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] + default = "WARNING" + bind = "log_level:__FINALPATH__/settings.py" diff --git a/scripts/_common.sh b/scripts/_common.sh index fee5921..b7efc0a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,6 +18,9 @@ app=$YNH_APP_INSTANCE_NAME # 'debug_enabled' -> '__DEBUG_ENABLED__' -> settings.DEBUG debug_enabled="0" +# 'log_level' -> '__LOG_LEVEL__' -> settings.LOG_LEVEL +log_level="WARNING" + #================================================= # SET CONSTANTS #================================================= diff --git a/scripts/install b/scripts/install index 5eab770..d75471e 100755 --- a/scripts/install +++ b/scripts/install @@ -60,8 +60,11 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) redis_db=$(ynh_redis_get_free_db) ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" -# Always deactivate settings.DEBUG: +#------------------------------------------------- +# config_panel.toml settings: + ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled" +ynh_app_setting_set --app="$app" --key=log_level --value="$log_level" #================================================= # STANDARD MODIFICATIONS diff --git a/scripts/upgrade b/scripts/upgrade index 9dfc208..e7db076 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,12 +29,21 @@ db_user=$db_name admin_mail=$(ynh_user_get_info "$admin" mail) redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) +#------------------------------------------------- +# config_panel.toml settings: + debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled) if [ -z "$debug_enabled" ]; then debug_enabled="0" ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled" fi +log_level=$(ynh_app_setting_get --app="$app" --key=log_level) +if [ -z "$log_level" ]; then + log_level="WARNING" + ynh_app_setting_set --app="$app" --key=log_level --value="$log_level" +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #=================================================