feat: Improve logging functions in backup scripts for better readability and structured output

This commit is contained in:
Peter Wood
2025-05-26 08:02:18 -04:00
parent 68f7f4ef8e
commit e90b9413de
4 changed files with 63 additions and 23 deletions

View File

@@ -170,35 +170,35 @@ log_message() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${CYAN}[${timestamp}]${NC} ${message}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $message" >> "${LOG_FILE}" 2>/dev/null || true
echo "[${timestamp}] $message" >> "${LOG_FILE}" 2>/dev/null || true
}
log_error() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${RED}[${timestamp}] ERROR:${NC} ${message}" >&2
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $message" >> "${LOG_FILE}" 2>/dev/null || true
echo "[${timestamp}] ERROR: $message" >> "${LOG_FILE}" 2>/dev/null || true
}
log_success() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${GREEN}[${timestamp}] SUCCESS:${NC} ${message}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] SUCCESS: $message" >> "${LOG_FILE}" 2>/dev/null || true
echo "[${timestamp}] SUCCESS: $message" >> "${LOG_FILE}" 2>/dev/null || true
}
log_warning() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${YELLOW}[${timestamp}] WARNING:${NC} ${message}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: $message" >> "${LOG_FILE}" 2>/dev/null || true
echo "[${timestamp}] WARNING: $message" >> "${LOG_FILE}" 2>/dev/null || true
}
log_info() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${BLUE}[${timestamp}] INFO:${NC} ${message}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $message" >> "${LOG_FILE}" 2>/dev/null || true
echo "[${timestamp}] INFO: $message" >> "${LOG_FILE}" 2>/dev/null || true
}
# Performance tracking functions