mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
Add '__LOG_LEVEL__' config_panel.toml settings
This commit is contained in:
parent
30f52f04dc
commit
82638455bd
5 changed files with 46 additions and 12 deletions
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
#=================================================
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue