From 7514e2ba7cc74c0b7dfbd0167a4d3813fdbeed76 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 10:50:45 -0500 Subject: [PATCH] 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 https://code.lotusguild.org/LotusGuild/proxDoc/issues/9 Co-Authored-By: Claude Opus 4.5 --- proxDoc.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/proxDoc.sh b/proxDoc.sh index 2ba5bfc..c7939ac 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -7,6 +7,12 @@ VERSION="1.1.0" ################### 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 ################### @@ -705,7 +711,28 @@ help() { ################### # 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() { + setup_logging log_message info "Beginning system examination..." # Check if running on Proxmox