From 7b1e6b0fd5149d32292574e7d414f3b57ffae13f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 29 Nov 2024 19:08:06 +0100 Subject: [PATCH] log --- sh/log.sh | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/sh/log.sh b/sh/log.sh index 2be59e0..9b2ffc4 100644 --- a/sh/log.sh +++ b/sh/log.sh @@ -1,68 +1,68 @@ -SH_LOG_LEVEL_FATAL=0 -SH_LOG_LEVEL_ERROR=1 -SH_LOG_LEVEL_WARN=2 -SH_LOG_LEVEL_INFO=3 -SH_LOG_LEVEL_DEBUG=4 -SH_LOG_LEVEL_TRACE=5 +RWX_LOG_LEVEL_FATAL=0 +RWX_LOG_LEVEL_ERROR=1 +RWX_LOG_LEVEL_WARN=2 +RWX_LOG_LEVEL_INFO=3 +RWX_LOG_LEVEL_DEBUG=4 +RWX_LOG_LEVEL_TRACE=5 -SH_LOG_LEVEL=${SH_LOG_LEVEL_INFO} +RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO} -sh_log() { sh_log_info "${@}"; } +rwx_log() { rwx_log_info "${@}"; } -sh_log_debug() { - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then - _sh_log "[DEBUG]" "${@}" +rwx_log_debug() { + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then + _rwx_log "[DEBUG]" "${@}" fi } -sh_log_error() { +rwx_log_error() { local code="${1}" shift - [ -n "${code}" ] || sh_log_fatal 1 "No error code" - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then - _sh_log "[ERROR]" "${@}" >&2 + [ -n "${code}" ] || rwx_log_fatal 1 "No error code" + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_ERROR}" ]; then + _rwx_log "[ERROR]" "${@}" >&2 return "${code}" fi } -sh_log_fatal() { +rwx_log_fatal() { local code="${1}" shift - [ -n "${code}" ] || sh_log_fatal 1 "No error code" - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then - _sh_log "[FATAL]" "${@}" >&2 + [ -n "${code}" ] || rwx_log_fatal 1 "No error code" + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_FATAL}" ]; then + _rwx_log "[FATAL]" "${@}" >&2 exit "${code}" fi } -sh_log_info() { - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then - _sh_log "" "${@}" +rwx_log_info() { + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then + _rwx_log "" "${@}" fi } -sh_log_trace() { - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then - _sh_log "[TRACE]" "${@}" +rwx_log_trace() { + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_TRACE}" ]; then + _rwx_log "[TRACE]" "${@}" fi } -sh_log_warn() { - if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then - _sh_log "[ WARN]" "${@}" +rwx_log_warn() { + if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_WARN}" ]; then + _rwx_log "[ WARN]" "${@}" fi } -_sh_log() { +_rwx_log() { local prefix="${1}" shift [ ${#} -gt 0 ] || set -- "" local line for line in "${@}"; do if [ -n "${prefix}" ]; then - _sh_main_log "${prefix} ${line}" + _rwx_main_log "${prefix} ${line}" else - _sh_main_log "${line}" + _rwx_main_log "${line}" fi done }