This commit is contained in:
Marc Beninca 2024-11-19 12:21:29 +01:00
parent 7dfbb947ff
commit d90f0fd6ef
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -11,7 +11,7 @@ sh_log() { sh_log_info "${@}"; }
sh_log_debug() { sh_log_debug() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then
echo "[DEBUG]" "${@}" _sh_log "[DEBUG]" "${@}"
fi fi
} }
@ -20,7 +20,7 @@ sh_log_error() {
shift shift
[ -n "${code}" ] || sh_log_fatal 1 "No error code" [ -n "${code}" ] || sh_log_fatal 1 "No error code"
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then
echo "[ERROR]" "${@}" >&2 _sh_log "[ERROR]" "${@}" >&2
return "${code}" return "${code}"
fi fi
} }
@ -30,25 +30,35 @@ sh_log_fatal() {
shift shift
[ -n "${code}" ] || sh_log_fatal 1 "No error code" [ -n "${code}" ] || sh_log_fatal 1 "No error code"
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then
echo "[FATAL]" "${@}" >&2 _sh_log "[FATAL]" "${@}" >&2
exit "${code}" exit "${code}"
fi fi
} }
sh_log_info() { sh_log_info() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then
echo "${@}" _sh_log "" "${@}"
fi fi
} }
sh_log_trace() { sh_log_trace() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then
echo "[TRACE]" "${@}" _sh_log "[TRACE]" "${@}"
fi fi
} }
sh_log_warn() { sh_log_warn() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then
echo " [WARN]" "${@}" _sh_log "[ WARN]" "${@}"
fi fi
} }
_sh_log() {
local prefix="${1}"
shift
local line
for line in "${@}"; do
printf "%s" "${prefix}"
echo " ${line}"
done
}