Skip to content

Commit 8fa6e6d

Browse files
authored
chore: Avoid logging a warning when LOG_LEVEL is unset (docker-mailserver#4497)
1 parent ea03808 commit 8fa6e6d

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

target/scripts/startup/variables-stack.sh

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
declare -A VARS
55

66
function _early_variables_setup() {
7-
__environment_variables_log_level
7+
__ensure_valid_log_level
88
__environment_variables_from_files
99
_obtain_hostname_and_domainname
1010
__environment_variables_backwards_compatibility
@@ -181,21 +181,11 @@ function __environment_variables_general_setup() {
181181
fi
182182
}
183183

184-
function __environment_variables_log_level() {
185-
if [[ ${LOG_LEVEL} == 'trace' ]] \
186-
|| [[ ${LOG_LEVEL} == 'debug' ]] \
187-
|| [[ ${LOG_LEVEL} == 'info' ]] \
188-
|| [[ ${LOG_LEVEL} == 'warn' ]] \
189-
|| [[ ${LOG_LEVEL} == 'error' ]]
190-
then
191-
return 0
192-
else
193-
local DEFAULT_LOG_LEVEL='info'
194-
_log 'warn' "Log level '${LOG_LEVEL}' is invalid (falling back to default '${DEFAULT_LOG_LEVEL}')"
195-
196-
# shellcheck disable=SC2034
197-
VARS[LOG_LEVEL]="${DEFAULT_LOG_LEVEL}"
198-
LOG_LEVEL="${DEFAULT_LOG_LEVEL}"
184+
# `LOG_LEVEL` must be set early to correctly filter calls to `scripts/helpers/log.sh:_log()`
185+
function __ensure_valid_log_level() {
186+
if [[ ! ${LOG_LEVEL:-info} =~ ^(trace|debug|info|warn|error)$ ]]; then
187+
_log 'warn' "Log level '${LOG_LEVEL}' is invalid (falling back to default: 'info')"
188+
LOG_LEVEL='info'
199189
fi
200190
}
201191

0 commit comments

Comments
 (0)