Add '__LOG_LEVEL__' config_panel.toml settings

This commit is contained in:
JensDiemer 2022-08-15 09:01:53 +02:00
parent 30f52f04dc
commit 82638455bd
5 changed files with 46 additions and 12 deletions

View file

@ -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 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 FINALPATH = __Path('__FINALPATH__') # /opt/yunohost/$app
assert FINALPATH.is_dir(), f'Directory not exists: {FINALPATH}' 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__' # $YNH_APP_ARG_PATH
PATH_URL = PATH_URL.strip('/') 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: # Function that will be called to finalize a user profile:
@ -111,6 +122,7 @@ else:
STATIC_ROOT = str(PUBLIC_PATH / 'static') STATIC_ROOT = str(PUBLIC_PATH / 'static')
MEDIA_ROOT = str(PUBLIC_PATH / 'media') MEDIA_ROOT = str(PUBLIC_PATH / 'media')
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
LOGGING = { LOGGING = {
@ -137,17 +149,17 @@ LOGGING = {
}, },
}, },
'loggers': { 'loggers': {
'': {'handlers': ['log_file', 'mail_admins'], 'level': 'INFO', 'propagate': False}, '': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False},
'django': {'handlers': ['log_file', 'mail_admins'], 'level': 'INFO', 'propagate': False}, 'django': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False},
'axes': {'handlers': ['log_file', 'mail_admins'], 'level': 'WARNING', 'propagate': False}, 'axes': {'handlers': ['log_file', 'mail_admins'], 'level': LOG_LEVEL, 'propagate': False},
'django_tools': { 'django_tools': {
'handlers': ['log_file', 'mail_admins'], 'handlers': ['log_file', 'mail_admins'],
'level': 'INFO', 'level': LOG_LEVEL,
'propagate': False, 'propagate': False,
}, },
'django_yunohost_integration': { 'django_yunohost_integration': {
'handlers': ['log_file', 'mail_admins'], 'handlers': ['log_file', 'mail_admins'],
'level': 'INFO', 'level': LOG_LEVEL,
'propagate': False, 'propagate': False,
}, },
}, },

View file

@ -14,3 +14,10 @@ services = ["__APP__"]
no = "0" no = "0"
help = "Should be never enabled in production!" help = "Should be never enabled in production!"
bind = "debug_enabled:__FINALPATH__/settings.py" 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"

View file

@ -18,6 +18,9 @@ app=$YNH_APP_INSTANCE_NAME
# 'debug_enabled' -> '__DEBUG_ENABLED__' -> settings.DEBUG # 'debug_enabled' -> '__DEBUG_ENABLED__' -> settings.DEBUG
debug_enabled="0" debug_enabled="0"
# 'log_level' -> '__LOG_LEVEL__' -> settings.LOG_LEVEL
log_level="WARNING"
#================================================= #=================================================
# SET CONSTANTS # SET CONSTANTS
#================================================= #=================================================

View file

@ -60,8 +60,11 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_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=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS

View file

@ -29,12 +29,21 @@ db_user=$db_name
admin_mail=$(ynh_user_get_info "$admin" mail) admin_mail=$(ynh_user_get_info "$admin" mail)
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) 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) debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
if [ -z "$debug_enabled" ]; then if [ -z "$debug_enabled" ]; then
debug_enabled="0" debug_enabled="0"
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled" ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
fi 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 # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================