From e6d0ef5a3b1a599be175f122a0464edaf5502bff Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 19 Aug 2019 21:41:39 +0200 Subject: [PATCH 1/3] :sparkles: Adds call to change log level --- lib/log.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/log.sh b/lib/log.sh index 102cb00..e407a5f 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -206,3 +206,48 @@ function bashio::log.fatal() { "${__BASHIO_LOG_LEVEL_FATAL}" \ "${__BASHIO_COLORS_RED}${message}${__BASHIO_COLORS_RESET}" } + +# ------------------------------------------------------------------------------ +# Changes the log level of Bashio on the fly. +# +# Arguments: +# $1 Log level +# ------------------------------------------------------------------------------ +function bashio::log.level() { + local level=${1} + + # Find the matching log level + case "$(bashio::string.lower "${level}")" in + all) + log_level="${__BASHIO_LOG_LEVEL_ALL}" + ;; + trace) + log_level="${__BASHIO_LOG_LEVEL_TRACE}" + ;; + debug) + log_level="${__BASHIO_LOG_LEVEL_DEBUG}" + ;; + info) + log_level="${__BASHIO_LOG_LEVEL_INFO}" + ;; + notice) + log_level="${__BASHIO_LOG_LEVEL_NOTICE}" + ;; + warning) + log_level="${__BASHIO_LOG_LEVEL_WARNING}" + ;; + error) + log_level="${__BASHIO_LOG_LEVEL_ERROR}" + ;; + fatal) + log_level="${__BASHIO_LOG_LEVEL_FATAL}" + ;; + off) + log_level="${__BASHIO_LOG_LEVEL_OFF}" + ;; + *) + bashio::exit.nok "Unknown log_level: ${log_level}" + esac + + export __BASHIO_LOG_LEVEL="${log_level}" +} From 26a5c51f463f38b958d878448d97ff000805015b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 19 Aug 2019 21:45:21 +0200 Subject: [PATCH 2/3] :pencil2: Map critical log level to fatal in Bashio --- lib/log.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/log.sh b/lib/log.sh index e407a5f..e50fa9b 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -239,7 +239,7 @@ function bashio::log.level() { error) log_level="${__BASHIO_LOG_LEVEL_ERROR}" ;; - fatal) + fatal|critical) log_level="${__BASHIO_LOG_LEVEL_FATAL}" ;; off) From 5dfd23bb5177d78297f6fbe98cd02f646c0e2f9f Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 19 Aug 2019 21:47:21 +0200 Subject: [PATCH 3/3] :ambulance: Fixes variable usage --- lib/log.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/log.sh b/lib/log.sh index e50fa9b..eeca90b 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -214,10 +214,10 @@ function bashio::log.fatal() { # $1 Log level # ------------------------------------------------------------------------------ function bashio::log.level() { - local level=${1} + local log_level=${1} # Find the matching log level - case "$(bashio::string.lower "${level}")" in + case "$(bashio::string.lower "${log_level}")" in all) log_level="${__BASHIO_LOG_LEVEL_ALL}" ;;