log
This commit is contained in:
parent
1bae77cd6a
commit
7b1e6b0fd5
1 changed files with 31 additions and 31 deletions
62
sh/log.sh
62
sh/log.sh
|
@ -1,68 +1,68 @@
|
||||||
SH_LOG_LEVEL_FATAL=0
|
RWX_LOG_LEVEL_FATAL=0
|
||||||
SH_LOG_LEVEL_ERROR=1
|
RWX_LOG_LEVEL_ERROR=1
|
||||||
SH_LOG_LEVEL_WARN=2
|
RWX_LOG_LEVEL_WARN=2
|
||||||
SH_LOG_LEVEL_INFO=3
|
RWX_LOG_LEVEL_INFO=3
|
||||||
SH_LOG_LEVEL_DEBUG=4
|
RWX_LOG_LEVEL_DEBUG=4
|
||||||
SH_LOG_LEVEL_TRACE=5
|
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() {
|
rwx_log_debug() {
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then
|
||||||
_sh_log "[DEBUG]" "${@}"
|
_rwx_log "[DEBUG]" "${@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_log_error() {
|
rwx_log_error() {
|
||||||
local code="${1}"
|
local code="${1}"
|
||||||
shift
|
shift
|
||||||
[ -n "${code}" ] || sh_log_fatal 1 "No error code"
|
[ -n "${code}" ] || rwx_log_fatal 1 "No error code"
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_ERROR}" ]; then
|
||||||
_sh_log "[ERROR]" "${@}" >&2
|
_rwx_log "[ERROR]" "${@}" >&2
|
||||||
return "${code}"
|
return "${code}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_log_fatal() {
|
rwx_log_fatal() {
|
||||||
local code="${1}"
|
local code="${1}"
|
||||||
shift
|
shift
|
||||||
[ -n "${code}" ] || sh_log_fatal 1 "No error code"
|
[ -n "${code}" ] || rwx_log_fatal 1 "No error code"
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_FATAL}" ]; then
|
||||||
_sh_log "[FATAL]" "${@}" >&2
|
_rwx_log "[FATAL]" "${@}" >&2
|
||||||
exit "${code}"
|
exit "${code}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_log_info() {
|
rwx_log_info() {
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then
|
||||||
_sh_log "" "${@}"
|
_rwx_log "" "${@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_log_trace() {
|
rwx_log_trace() {
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_TRACE}" ]; then
|
||||||
_sh_log "[TRACE]" "${@}"
|
_rwx_log "[TRACE]" "${@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_log_warn() {
|
rwx_log_warn() {
|
||||||
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then
|
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_WARN}" ]; then
|
||||||
_sh_log "[ WARN]" "${@}"
|
_rwx_log "[ WARN]" "${@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_sh_log() {
|
_rwx_log() {
|
||||||
local prefix="${1}"
|
local prefix="${1}"
|
||||||
shift
|
shift
|
||||||
[ ${#} -gt 0 ] || set -- ""
|
[ ${#} -gt 0 ] || set -- ""
|
||||||
local line
|
local line
|
||||||
for line in "${@}"; do
|
for line in "${@}"; do
|
||||||
if [ -n "${prefix}" ]; then
|
if [ -n "${prefix}" ]; then
|
||||||
_sh_main_log "${prefix} ${line}"
|
_rwx_main_log "${prefix} ${line}"
|
||||||
else
|
else
|
||||||
_sh_main_log "${line}"
|
_rwx_main_log "${line}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue