Skip to content

Commit

Permalink
Adds call to change log level (#13)
Browse files Browse the repository at this point in the history
* ✨ Adds call to change log level

* ✏️ Map critical log level to fatal in Bashio

* 🚑 Fixes variable usage
  • Loading branch information
frenck authored Aug 19, 2019
1 parent abf27b4 commit de8d102
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 log_level=${1}

# Find the matching log level
case "$(bashio::string.lower "${log_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|critical)
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}"
}

0 comments on commit de8d102

Please sign in to comment.