Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds call to change log level #13

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
}