Add conditional logging based on logging_level

This commit is contained in:
icenine451 2024-10-18 09:40:28 -04:00
parent ef9b5024fd
commit a5eba709d9

View file

@ -41,6 +41,7 @@ log() {
case "$level" in
d)
if [[ $logging_level == "debug" ]]; then
if [ "$colorize_terminal" = true ]; then
# Debug (green) for terminal
colored_message="\e[32m[DEBUG] $message\e[0m"
@ -50,8 +51,10 @@ log() {
fi
# Write to log file without colorization
log_message="$timestamp [DEBUG] $message"
fi
;;
e)
if [[ $logging_level == "debug" || $logging_level == "error" ]]; then
if [ "$colorize_terminal" = true ]; then
# Error (red) for terminal
colored_message="\e[31m[ERROR] $message\e[0m"
@ -61,8 +64,10 @@ log() {
fi
# Write to log file without colorization
log_message="$timestamp [ERROR] $message"
fi
;;
w)
if [[ $logging_level == "debug" || $logging_level == "error" || $logging_level == "warn" ]]; then
if [ "$colorize_terminal" = true ]; then
# Warning (yellow) for terminal
colored_message="\e[33m[WARN] $message\e[0m"
@ -72,11 +77,14 @@ log() {
fi
# Write to log file without colorization
log_message="$timestamp [WARN] $message"
fi
;;
i)
if [[ $logging_level == "debug" || $logging_level == "error" || $logging_level == "warn" || $logging_level == "info" ]]; then
# Write to log file without colorization for info message
log_message="$timestamp [INFO] $message"
colored_message=$log_message
fi
;;
*)
# Default (no color for other shells) for terminal