mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 05:40:11 -08:00
feat: Improve logging functions in backup scripts for better readability and structured output
This commit is contained in:
@@ -17,7 +17,19 @@ MAX_INSTALL_ATTEMPTS=3
|
||||
CURRENT_ATTEMPT=1
|
||||
|
||||
# Log file
|
||||
# Create logs directory if it doesn't exist and is writable
|
||||
# C log_both "\n${BLUE}Debugging lolcat package:${NC}" "Debugging lolcat package:"
|
||||
if [ -f "/usr/games/lolcat" ]; then
|
||||
log_both "- Lolcat found at /usr/games/lolcat"
|
||||
ls -la /usr/games/lolcat >> "$LOG_FILE"
|
||||
else
|
||||
log_both "- Lolcat not found at /usr/games/lolcat"
|
||||
fi
|
||||
if check_command lolcat; then
|
||||
log_both "- Lolcat found in PATH"
|
||||
command -v lolcat >> "$LOG_FILE"
|
||||
else
|
||||
log_both "- Lolcat not found in PATH"
|
||||
firectory if it doesn't exist and is writable
|
||||
# First, try creating the logs directory in case it doesn't exist
|
||||
if [ -d "/logs" ] || mkdir -p /logs 2>/dev/null; then
|
||||
if [ -w "/logs" ]; then
|
||||
@@ -52,6 +64,23 @@ echo "Starting setup test at $(date)" > "$LOG_FILE" || {
|
||||
echo "Starting setup test at $(date)" > "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Helper function to log colored output to terminal and clean output to file
|
||||
log_both() {
|
||||
local colored_message="$1"
|
||||
local clean_message="$2"
|
||||
|
||||
# Display colored message to terminal
|
||||
echo -e "$colored_message"
|
||||
|
||||
# Log clean message to file
|
||||
if [ -n "$clean_message" ]; then
|
||||
echo "$clean_message" >> "$LOG_FILE"
|
||||
else
|
||||
# Strip ANSI escape codes for file logging
|
||||
echo "$colored_message" | sed 's/\x1b\[[0-9;]*m//g' >> "$LOG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Identify the system
|
||||
echo -e "${BLUE}=== System Information ===${NC}"
|
||||
if [ -f /etc/os-release ]; then
|
||||
@@ -423,18 +452,18 @@ while [ $CURRENT_ATTEMPT -le $MAX_INSTALL_ATTEMPTS ]; do
|
||||
;;
|
||||
"cowsay")
|
||||
# Extra debugging for cowsay
|
||||
echo -e "\n${BLUE}Debugging cowsay package:${NC}" | tee -a "$LOG_FILE"
|
||||
log_both "\n${BLUE}Debugging cowsay package:${NC}" "Debugging cowsay package:"
|
||||
if [ -f "/usr/games/cowsay" ]; then
|
||||
echo -e "- Cowsay found at /usr/games/cowsay" | tee -a "$LOG_FILE"
|
||||
ls -la /usr/games/cowsay | tee -a "$LOG_FILE"
|
||||
log_both "- Cowsay found at /usr/games/cowsay"
|
||||
ls -la /usr/games/cowsay >> "$LOG_FILE"
|
||||
else
|
||||
echo -e "- Cowsay not found at /usr/games/cowsay" | tee -a "$LOG_FILE"
|
||||
log_both "- Cowsay not found at /usr/games/cowsay"
|
||||
fi
|
||||
if check_command cowsay; then
|
||||
echo -e "- Cowsay found in PATH" | tee -a "$LOG_FILE"
|
||||
command -v cowsay | tee -a "$LOG_FILE"
|
||||
log_both "- Cowsay found in PATH"
|
||||
command -v cowsay >> "$LOG_FILE"
|
||||
else
|
||||
echo -e "- Cowsay not found in PATH" | tee -a "$LOG_FILE"
|
||||
log_both "- Cowsay not found in PATH"
|
||||
fi
|
||||
|
||||
if ! test_package "cowsay" "cowsay"; then
|
||||
|
||||
Reference in New Issue
Block a user