Add logging infrastructure without subshell overhead

Add optional logging to file via PROXDOC_LOGFILE environment
variable. Uses exec redirection with tee instead of subshells,
which is more efficient for long-running diagnostics.

Usage: PROXDOC_LOGFILE=/tmp/proxdoc.log ./proxDoc.sh --diags

#9

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 10:50:45 -05:00
parent f7ed682bdb
commit 7514e2ba7c

View File

@@ -7,6 +7,12 @@ VERSION="1.1.0"
################### ###################
readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands
###################
# Logging Configuration
###################
# Optional log file - set via environment variable PROXDOC_LOGFILE
LOGFILE="${PROXDOC_LOGFILE:-}"
################### ###################
# Pattern Constants # Pattern Constants
################### ###################
@@ -705,7 +711,28 @@ help() {
################### ###################
# Main Functions # Main Functions
################### ###################
# Setup logging if LOGFILE is specified
setup_logging() {
if [[ -n "$LOGFILE" ]]; then
# Create log directory if needed
local log_dir
log_dir=$(dirname "$LOGFILE")
if [[ ! -d "$log_dir" ]]; then
mkdir -p "$log_dir" 2>/dev/null || {
log_message warn "Cannot create log directory: $log_dir"
LOGFILE=""
return
}
fi
log_message info "Logging output to: $LOGFILE"
# Redirect stdout and stderr to tee (no subshell overhead)
exec > >(tee -a "$LOGFILE") 2>&1
fi
}
runDiags() { runDiags() {
setup_logging
log_message info "Beginning system examination..." log_message info "Beginning system examination..."
# Check if running on Proxmox # Check if running on Proxmox