mirror of
https://github.com/angristan/openvpn-install.git
synced 2025-12-16 00:47:02 +01:00
Add structured logging system with color-coded output and file logging (#1321)
## Summary - Add comprehensive logging system with color-coded log levels ([INFO], [WARN], [ERROR], [OK]) - Wrap all command executions with `run_cmd()` to capture output and prevent leaks to stdout - Add file logging with timestamps (default: `openvpn-install.log`) - Suppress interactive prompts in auto-install mode for cleaner CI/scripted usage - Show log file location hint on errors for easier debugging ## Changes - **openvpn-install.sh**: New logging functions (`log_info`, `log_warn`, `log_error`, `log_fatal`, `log_success`, `log_prompt`, `log_header`, `log_menu`, `run_cmd`), all `echo` statements converted to use logging functions - **test/validate-output.sh**: New E2E validator that ensures all script output uses proper log formatting (catches raw echo leaks) - **test/server-entrypoint.sh**: Integrates output validation into Docker tests - **test/Dockerfile.server**: Copies validation script into container ## Configuration - `VERBOSE=1` - Show command output in terminal - `LOG_FILE=path` - Customize log location (default: `openvpn-install.log`) - `LOG_FILE=""` - Disable file logging - `FORCE_COLOR=1` - Force colored output in non-TTY environments
This commit is contained in:
@@ -14,6 +14,7 @@ echo "TUN device ready"
|
||||
|
||||
# Set up environment for auto-install
|
||||
export AUTO_INSTALL=y
|
||||
export FORCE_COLOR=1
|
||||
export APPROVE_INSTALL=y
|
||||
export APPROVE_IP=y
|
||||
export IPV6_SUPPORT=n
|
||||
@@ -34,11 +35,24 @@ chmod +x /tmp/openvpn-install.sh
|
||||
|
||||
echo "Running OpenVPN install script..."
|
||||
# Run in subshell because the script calls 'exit 0' after generating client config
|
||||
# Capture output to validate logging format, while still displaying it
|
||||
# Use || true to prevent set -e from exiting on failure, then check exit code
|
||||
(bash -x /tmp/openvpn-install.sh) && INSTALL_EXIT_CODE=0 || INSTALL_EXIT_CODE=$?
|
||||
INSTALL_OUTPUT="/tmp/install-output.log"
|
||||
(bash /tmp/openvpn-install.sh) 2>&1 | tee "$INSTALL_OUTPUT"
|
||||
INSTALL_EXIT_CODE=${PIPESTATUS[0]}
|
||||
|
||||
echo "=== Installation complete (exit code: $INSTALL_EXIT_CODE) ==="
|
||||
|
||||
# Validate that all output uses proper logging format (ANSI color codes)
|
||||
echo "Validating output format..."
|
||||
if /opt/test/validate-output.sh "$INSTALL_OUTPUT"; then
|
||||
echo "PASS: All script output uses proper log formatting"
|
||||
else
|
||||
echo "FAIL: Script output contains unformatted lines"
|
||||
echo "This indicates echo statements that should use log_* functions"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$INSTALL_EXIT_CODE" -ne 0 ]; then
|
||||
echo "ERROR: Install script failed with exit code $INSTALL_EXIT_CODE"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user