sconnect/lib/logger

37 lines
565 B
Text
Raw Normal View History

2024-06-02 22:13:33 +02:00
#!/bin/sh
2024-06-06 02:00:49 +02:00
# levels:
# DEBUG = 0
# INFO = 1
# WARN = 2
# ERROR = 3
SC_LOGGER_LEVEL=${SC_LOGGER_LEVEL:-1}
__sc_log_level_to_text() {
case $1 in
0) echo "debug" ;;
1) echo "info" ;;
2) echo "warn" ;;
3) echo "error" ;;
4) echo "fatal" ;;
esac
}
2024-06-02 22:13:33 +02:00
__sc_log() {
2024-06-06 02:00:49 +02:00
level=$1
shift
if [ "$level" -ge "$SC_LOGGER_LEVEL" ]; then
echo "[$(__sc_log_level_to_text $level)] $@"
fi
2024-06-02 22:13:33 +02:00
}
2024-06-06 02:00:49 +02:00
alias LOGD="__sc_log 0"
alias LOGI="__sc_log 1"
alias LOGW="__sc_log 2"
alias LOGE="__sc_log 3"
2024-06-02 22:13:33 +02:00
fatal_log() {
2024-06-06 02:00:49 +02:00
__sc_log 4 $@
2024-06-02 22:13:33 +02:00
exit 1
2024-06-06 02:00:49 +02:00
}