Skip to content

Commit fab1915

Browse files
committed
Logging and Monitoring support
1 parent 73022eb commit fab1915

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ Enter your menu choice [1-12]:
130130
🔹 **More Comprehensive IP Discovery** – Improved detection across networks.
131131
🔹 **Automated Backup & Restore** – Protect your Empire with scheduled snapshots.
132132
🔹 **Live VM Migration** – Move VMs across hosts without downtime.
133-
🔹 **Enhanced Logging & Monitoring** – A Sith Lord must always be aware.
134133
🔹 **Dark Mode UI for CLI** – Because the Dark Side always looks better.
135134
136135
>*"Once you start down the VaderShell path, forever will it dominate your destiny."*

VaderShell.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,61 @@
33
# Load configuration file
44
source config.cfg
55

6+
# ===================== Logging toggle (drop-in) =====================
7+
# Assumes config.cfg already sourced above.
8+
: "${VADERSHELL_LOG_ENABLED:=1}"
9+
: "${VADERSHELL_LOG_MODE:=tee}"
10+
: "${VADERSHELL_LOG_DIR:=$HOME/.vadershell/logs}"
11+
: "${VADERSHELL_LOG_FILE:=}"
12+
: "${VADERSHELL_TRACE:=0}"
13+
14+
if [[ "$VADERSHELL_LOG_ENABLED" == "1" ]]; then
15+
mkdir -p "$VADERSHELL_LOG_DIR"
16+
SCRIPT_NAME="$(basename "$0")"
17+
START_TS="$(date +"%Y%m%d-%H%M%S")"
18+
if [[ -z "$VADERSHELL_LOG_FILE" ]]; then
19+
VADERSHELL_LOG_FILE="$VADERSHELL_LOG_DIR/${SCRIPT_NAME%.*}_${START_TS}.log"
20+
else
21+
mkdir -p "$(dirname "$VADERSHELL_LOG_FILE")"
22+
fi
23+
24+
case "$VADERSHELL_LOG_MODE" in
25+
tee)
26+
exec > >(stdbuf -i0 -o0 -e0 tee -a "$VADERSHELL_LOG_FILE") 2>&1
27+
;;
28+
ts-file)
29+
# Console: raw; File: timestamped (pure bash)
30+
exec > >(tee >(stdbuf -i0 -o0 -e0 bash -c '
31+
f="$1"
32+
while IFS= read -r line; do
33+
printf "[%(%Y-%m-%d %H:%M:%S)T] %s\n" -1 "$line"
34+
done >> "$f"
35+
' _ "$VADERSHELL_LOG_FILE")) 2>&1
36+
;;
37+
ts-both)
38+
# Console + File: timestamped (⚠ single-line prompts may appear late on console)
39+
exec > >(bash -c '
40+
f="$1"
41+
while IFS= read -r line; do
42+
printf "[%(%Y-%m-%d %H:%M:%S)T] %s\n" -1 "$line" | tee -a "$f"
43+
done
44+
' _ "$VADERSHELL_LOG_FILE") 2>&1
45+
;;
46+
none|*)
47+
:
48+
;;
49+
esac
50+
51+
echo "[INFO] Log enabled: $VADERSHELL_LOG_MODE -> $VADERSHELL_LOG_FILE"
52+
53+
if [[ "$VADERSHELL_TRACE" == "1" ]]; then
54+
export PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE##*/}:${LINENO}:${FUNCNAME[0]:-main}: '
55+
set -x
56+
fi
57+
fi
58+
# =================== End logging toggle block ======================
59+
60+
661
declare -A vm_list
762
declare -i total_vms=0
863
declare -i total_servers=${#SERVERS[@]}

config.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
###--- logging config --- ###
2+
VADERSHELL_LOG_ENABLED=1 #1 = enable logging, 0 = no logging at all
3+
4+
# Mode: none | tee | ts-file | ts-both
5+
# - tee: console raw, logfile raw (best for interactive prompts)
6+
# - ts-file: console raw, logfile timestamped (recommended)
7+
# - ts-both: console + logfile timestamped (prompts may appear late)
8+
VADERSHELL_LOG_MODE=tee
9+
10+
# Where to store logs (can be absolute or use $HOME)
11+
VADERSHELL_LOG_DIR="$HOME/.vadershell/logs"
12+
13+
# Optional fixed logfile path; leave empty to auto-name per run
14+
VADERSHELL_LOG_FILE=""
15+
16+
# Shell trace (xtrace). 1 = enable, 0 = disable
17+
VADERSHELL_TRACE=0
18+
### --- end logging config --- ###
19+
120
# List of servers in the format <hostname>:<user>@<hostname>
221
SERVERS=(
322
"server1:user1@server1"

0 commit comments

Comments
 (0)