Add logging function with improved output formatting

- Introduced a log() function to capture console output to a file
- Added date separator and blank lines for better readability
- Stripped ANSI color codes to avoid strange characters in the log
This commit is contained in:
2025-01-04 19:47:31 +09:00
parent 6642d5a265
commit 501d29cad7
3 changed files with 19 additions and 5 deletions
+1
View File
@@ -1,2 +1,3 @@
caddy/* caddy/*
wordpress/* wordpress/*
kazewp.log
+4
View File
@@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
LOG_FILE="kazewp.log"
exec > >(tee -a "$LOG_FILE") 2>&1
echo -e "\n========== $(date '+%Y-%m-%d %H:%M:%S') =========="
# Get the directory where the script is located # Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+10 -1
View File
@@ -1,4 +1,13 @@
if [ -t 1 ]; then
# Terminal supports colors
NC='\033[0m' # No Color
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
BLUE='\033[0;34m' BLUE='\033[0;34m'
NC='\033[0m' # No Color else
# Disable colors for non-terminal outputs (like logs)
NC=''
RED=''
GREEN=''
BLUE=''
fi