changed the logging
This commit is contained in:
parent
cfec752bf3
commit
c2b4018cfa
1 changed files with 28 additions and 44 deletions
70
.zshrc
70
.zshrc
|
@ -6,58 +6,42 @@ YELLOW='\033[0;33m'
|
|||
LIGHT_GREEN='\033[0;92m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m' # No Color
|
||||
_STORED_ERRORS=""
|
||||
_STORED_WARNINGS=""
|
||||
_STORED_INFOS=""
|
||||
|
||||
# Modified echo functions that both store and display messages
|
||||
function echo_error() {
|
||||
local message="${RED}$1${NC}\n"
|
||||
printf "$message" >&2
|
||||
_STORED_ERRORS="${_STORED_ERRORS}${message}"
|
||||
# Message storage
|
||||
declare -A _MESSAGES=([error]="" [warn]="" [info]="")
|
||||
|
||||
# Logging functions with emojis
|
||||
echo_error() {
|
||||
local msg="${RED}❌ $1${NC}\n"
|
||||
printf "$msg" >&2
|
||||
_MESSAGES[error]+="$msg"
|
||||
}
|
||||
|
||||
function echo_warning() {
|
||||
local message="${YELLOW}$1${NC}\n"
|
||||
printf "$message"
|
||||
_STORED_WARNINGS="${_STORED_WARNINGS}${message}"
|
||||
echo_warning() {
|
||||
local msg="${YELLOW}⚠️ $1${NC}\n"
|
||||
printf "$msg"
|
||||
_MESSAGES[warn]+="$msg"
|
||||
}
|
||||
|
||||
function echo_info() {
|
||||
local message="${CYAN}$1${NC}\n"
|
||||
printf "$message"
|
||||
_STORED_INFOS="${_STORED_INFOS}${message}"
|
||||
echo_info() {
|
||||
local msg="${CYAN}ℹ️ $1${NC}\n"
|
||||
printf "$msg"
|
||||
_MESSAGES[info]+="$msg"
|
||||
}
|
||||
|
||||
# Display stored messages
|
||||
error_log() {
|
||||
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0
|
||||
|
||||
# Function to display all stored messages
|
||||
function error_log() {
|
||||
local has_messages=0
|
||||
local headers=([error]="❌ Errors" [warn]="⚠️ Warnings" [info]="ℹ️ Info")
|
||||
local colors=([error]="$RED" [warn]="$YELLOW" [info]="$CYAN")
|
||||
|
||||
# First check if we have any messages at all
|
||||
if [ -z "$_STORED_ERRORS" ] && [ -z "$_STORED_WARNINGS" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Only display sections that have content
|
||||
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
|
||||
for type in error warn info; do
|
||||
[[ -n "${_MESSAGES[$type]}" ]] && {
|
||||
printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n"
|
||||
printf "${_MESSAGES[$type]}"
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue