From d90f0fd6ef960425a4f9a59a65e121352264ca79 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 19 Nov 2024 12:21:29 +0100 Subject: [PATCH] _sh_log --- sh/log.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sh/log.sh b/sh/log.sh index 34e986f..40cb311 100644 --- a/sh/log.sh +++ b/sh/log.sh @@ -11,7 +11,7 @@ sh_log() { sh_log_info "${@}"; } sh_log_debug() { if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then - echo "[DEBUG]" "${@}" + _sh_log "[DEBUG]" "${@}" fi } @@ -20,7 +20,7 @@ sh_log_error() { shift [ -n "${code}" ] || sh_log_fatal 1 "No error code" if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then - echo "[ERROR]" "${@}" >&2 + _sh_log "[ERROR]" "${@}" >&2 return "${code}" fi } @@ -30,25 +30,35 @@ sh_log_fatal() { shift [ -n "${code}" ] || sh_log_fatal 1 "No error code" if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then - echo "[FATAL]" "${@}" >&2 + _sh_log "[FATAL]" "${@}" >&2 exit "${code}" fi } sh_log_info() { if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then - echo "${@}" + _sh_log "" "${@}" fi } sh_log_trace() { if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then - echo "[TRACE]" "${@}" + _sh_log "[TRACE]" "${@}" fi } sh_log_warn() { if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then - echo " [WARN]" "${@}" + _sh_log "[ WARN]" "${@}" fi } + +_sh_log() { + local prefix="${1}" + shift + local line + for line in "${@}"; do + printf "%s" "${prefix}" + echo " ${line}" + done +} \ No newline at end of file