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