initial env

This commit is contained in:
Sebastian Rust
2024-06-09 19:01:16 +02:00
commit d353787c1a
28 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env zsh
declare -A levels=([DEBUG]=0 [INFO]=1 [WARN]=2 [ERROR]=3)
# LOG_LEVEL="DEBUG"
logger() {
if [ -z ${LOG_LEVEL+x} ]; then
return 3
fi
local log_message=$1
local log_priority=$2
#check if level exists
[[ ${levels[$log_priority]} ]] || return 1
#check if level is enough
(( ${levels[$log_priority]} < ${levels[$LOG_LEVEL]} )) && return 2
#log here
echo "${log_priority} : ${log_message}"
}
logger.debug(){
logger $1 "DEBUG"
}
logger.info(){
logger $1 "INFO"
}
logger.warn(){
logger $1 "WARN"
}
logger.error(){
logger $1 "ERROR"
}