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
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue