rwx/sh/log.sh
2024-11-18 12:07:42 +01:00

44 lines
775 B
Bash

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
SH_LOG_LEVEL=${SH_LOG_LEVEL_INFO}
log_debug() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_DEBUG}" ]; then
echo "[DEBUG]" "${@}"
fi
}
log_error() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_ERROR}" ]; then
echo "[ERROR]" "${@}"
fi
}
log_fatal() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_FATAL}" ]; then
echo "[FATAL]" "${@}"
fi
}
log_info() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_INFO}" ]; then
echo "${@}"
fi
}
log_trace() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_TRACE}" ]; then
echo "[TRACE]" "${@}"
fi
}
log_warn() {
if [ "${SH_LOG_LEVEL}" -ge "${SH_LOG_LEVEL_WARN}" ]; then
echo " [WARN]" "${@}"
fi
}