changed the logging

This commit is contained in:
piecka 2024-12-18 15:02:28 +01:00
parent cfec752bf3
commit c2b4018cfa

70
.zshrc
View file

@ -6,58 +6,42 @@ YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m' LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m' BOLD='\033[1m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
_STORED_ERRORS=""
_STORED_WARNINGS=""
_STORED_INFOS=""
# Modified echo functions that both store and display messages # Message storage
function echo_error() { declare -A _MESSAGES=([error]="" [warn]="" [info]="")
local message="${RED}$1${NC}\n"
printf "$message" >&2 # Logging functions with emojis
_STORED_ERRORS="${_STORED_ERRORS}${message}" echo_error() {
local msg="${RED}$1${NC}\n"
printf "$msg" >&2
_MESSAGES[error]+="$msg"
} }
function echo_warning() { echo_warning() {
local message="${YELLOW}$1${NC}\n" local msg="${YELLOW}⚠️ $1${NC}\n"
printf "$message" printf "$msg"
_STORED_WARNINGS="${_STORED_WARNINGS}${message}" _MESSAGES[warn]+="$msg"
} }
function echo_info() { echo_info() {
local message="${CYAN}$1${NC}\n" local msg="${CYAN} $1${NC}\n"
printf "$message" printf "$msg"
_STORED_INFOS="${_STORED_INFOS}${message}" _MESSAGES[info]+="$msg"
} }
# Display stored messages
error_log() {
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0
# Function to display all stored messages local headers=([error]="❌ Errors" [warn]="⚠️ Warnings" [info]=" Info")
function error_log() { local colors=([error]="$RED" [warn]="$YELLOW" [info]="$CYAN")
local has_messages=0
# First check if we have any messages at all for type in error warn info; do
if [ -z "$_STORED_ERRORS" ] && [ -z "$_STORED_WARNINGS" ]; then [[ -n "${_MESSAGES[$type]}" ]] && {
return 0 printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n"
fi printf "${_MESSAGES[$type]}"
}
# Only display sections that have content done
if [ -n "$_STORED_ERRORS" ]; then
printf "\n${BOLD}${RED}=== Errors ===${NC}\n"
printf "$_STORED_ERRORS"
has_messages=1
fi
if [ -n "$_STORED_WARNINGS" ]; then
printf "\n${BOLD}${YELLOW}=== Warnings ===${NC}\n"
printf "$_STORED_WARNINGS"
has_messages=1
fi
if [ -n "$_STORED_INFOS" ]; then
[ "$has_messages" -eq 1 ] && printf "\n"
printf "${BOLD}${CYAN}=== Info ===${NC}\n"
printf "$_STORED_INFOS"
has_messages=1
fi
} }
# ─< Check if the given command exists silently >───────────────────────────────────────── # ─< Check if the given command exists silently >─────────────────────────────────────────