Enhance logging and monitoring capabilities
- Added a new section in `REBUILD.md` for watching activity logs with usage instructions for different modes. - Updated `rebuild.sh` to dynamically set the log file path and provide clearer log viewing instructions. - Enhanced `watch-activity.sh` to support monitoring both systemd journal logs and specified log files, with improved error handling and user guidance.
This commit is contained in:
parent
1e7a47ad31
commit
f4155cf820
12
REBUILD.md
12
REBUILD.md
@ -32,6 +32,18 @@ tail -f /tmp/mirrormatch-server.log
|
|||||||
### Development Mode
|
### Development Mode
|
||||||
Logs appear directly in the terminal (foreground mode)
|
Logs appear directly in the terminal (foreground mode)
|
||||||
|
|
||||||
|
### Watching Activity Logs
|
||||||
|
```bash
|
||||||
|
# If using rebuild.sh (production mode)
|
||||||
|
./watch-activity.sh /tmp/mirrormatch-server.log
|
||||||
|
|
||||||
|
# If using systemd service
|
||||||
|
./watch-activity.sh
|
||||||
|
|
||||||
|
# Or specify custom log file
|
||||||
|
./watch-activity.sh /path/to/your/logfile.log
|
||||||
|
```
|
||||||
|
|
||||||
## Manual Commands
|
## Manual Commands
|
||||||
|
|
||||||
If you prefer to run commands manually:
|
If you prefer to run commands manually:
|
||||||
|
|||||||
14
rebuild.sh
14
rebuild.sh
@ -6,11 +6,16 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Get the directory where this script is located
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
MODE=${1:-prod}
|
MODE=${1:-prod}
|
||||||
|
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
echo "MirrorMatch - Clean Rebuild & Start"
|
echo "MirrorMatch - Clean Rebuild & Start"
|
||||||
echo "Mode: ${MODE}"
|
echo "Mode: ${MODE}"
|
||||||
|
echo "Working directory: $SCRIPT_DIR"
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
|
|
||||||
# Step 1: Kill everything
|
# Step 1: Kill everything
|
||||||
@ -33,7 +38,6 @@ echo "✓ Ports freed"
|
|||||||
# Step 3: Clean build artifacts
|
# Step 3: Clean build artifacts
|
||||||
echo ""
|
echo ""
|
||||||
echo "Step 3: Cleaning build artifacts..."
|
echo "Step 3: Cleaning build artifacts..."
|
||||||
cd /home/beast/Code/mirrormatch
|
|
||||||
rm -rf .next node_modules/.cache .next/cache .next/dev/lock 2>/dev/null || true
|
rm -rf .next node_modules/.cache .next/cache .next/dev/lock 2>/dev/null || true
|
||||||
echo "✓ Build artifacts cleaned"
|
echo "✓ Build artifacts cleaned"
|
||||||
|
|
||||||
@ -59,19 +63,21 @@ if [ "$MODE" = "dev" ]; then
|
|||||||
unset AUTH_TRUST_HOST
|
unset AUTH_TRUST_HOST
|
||||||
npm run dev
|
npm run dev
|
||||||
else
|
else
|
||||||
|
LOG_FILE="${LOG_FILE:-/tmp/mirrormatch-server.log}"
|
||||||
echo "Production mode - server running in background"
|
echo "Production mode - server running in background"
|
||||||
echo "View logs: tail -f /tmp/mirrormatch-server.log"
|
echo "View logs: tail -f $LOG_FILE"
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
echo ""
|
echo ""
|
||||||
export NODE_ENV=production
|
export NODE_ENV=production
|
||||||
unset AUTH_TRUST_HOST
|
unset AUTH_TRUST_HOST
|
||||||
npm run start > /tmp/mirrormatch-server.log 2>&1 &
|
npm run start > "$LOG_FILE" 2>&1 &
|
||||||
echo "Server PID: $!"
|
echo "Server PID: $!"
|
||||||
|
echo "Log file: $LOG_FILE"
|
||||||
echo ""
|
echo ""
|
||||||
sleep 3
|
sleep 3
|
||||||
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200\|307"; then
|
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200\|307"; then
|
||||||
echo "✓ Server is running on http://localhost:3000"
|
echo "✓ Server is running on http://localhost:3000"
|
||||||
else
|
else
|
||||||
echo "⚠ Server may still be starting. Check logs: tail -f /tmp/mirrormatch-server.log"
|
echo "⚠ Server may still be starting. Check logs: tail -f $LOG_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
74
watch-activity.sh
Normal file → Executable file
74
watch-activity.sh
Normal file → Executable file
@ -1,29 +1,65 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Watch user activity logs in real-time
|
# Watch user activity logs in real-time
|
||||||
#
|
#
|
||||||
# This script monitors systemd journal logs for MirrorMatch activity.
|
# This script monitors logs for MirrorMatch activity.
|
||||||
# It filters for activity-related log entries including page visits, photo uploads, and guess submissions.
|
# It can watch systemd journal logs OR application log files.
|
||||||
#
|
#
|
||||||
# Usage: ./watch-activity.sh
|
# Usage: ./watch-activity.sh [logfile]
|
||||||
|
# - No argument: Try systemd journal (requires systemd service)
|
||||||
|
# - With argument: Watch specified log file (e.g., ./watch-activity.sh /tmp/mirrormatch-server.log)
|
||||||
#
|
#
|
||||||
# Requirements:
|
# For local development:
|
||||||
# - Systemd/journalctl (Linux systems with systemd)
|
# - If running via rebuild.sh: ./watch-activity.sh /tmp/mirrormatch-server.log
|
||||||
# - Appropriate permissions (may require sudo)
|
# - If running via npm run dev: ./watch-activity.sh app.log (if you redirect output)
|
||||||
# - Application running as a systemd service named "app-backend"
|
# - If running as systemd service: ./watch-activity.sh (uses journalctl)
|
||||||
#
|
|
||||||
# For local development without systemd:
|
LOG_FILE="${1:-}"
|
||||||
# - Check application console output directly
|
|
||||||
# - Use `npm run dev` and monitor terminal output
|
|
||||||
# - Or redirect logs to a file and tail it: `npm run dev > app.log 2>&1 && tail -f app.log`
|
|
||||||
#
|
|
||||||
# Note: With the new structured logging system, you can also filter by log level:
|
|
||||||
# - Set LOG_LEVEL=DEBUG to see all activity logs
|
|
||||||
# - Set LOG_FORMAT=json for structured JSON logs
|
|
||||||
|
|
||||||
echo "Watching user activity logs..."
|
echo "Watching user activity logs..."
|
||||||
echo "Press Ctrl+C to stop"
|
echo "Press Ctrl+C to stop"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Watch for activity logs (ACTIVITY, PHOTO_UPLOAD, GUESS_SUBMIT)
|
if [ -n "$LOG_FILE" ]; then
|
||||||
# These patterns match the activity log format from lib/activity-log.ts
|
# Watch log file
|
||||||
sudo journalctl -u app-backend -f | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:"
|
if [ ! -f "$LOG_FILE" ]; then
|
||||||
|
echo "⚠ Warning: Log file '$LOG_FILE' does not exist yet."
|
||||||
|
echo " Waiting for it to be created..."
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
tail -f "$LOG_FILE" 2>/dev/null | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:|INFO.*Activity:"
|
||||||
|
elif systemctl is-active --quiet app-backend 2>/dev/null; then
|
||||||
|
# Use systemd journal if service is active
|
||||||
|
echo "Using systemd journal (app-backend service)"
|
||||||
|
echo ""
|
||||||
|
sudo journalctl -u app-backend -f | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:|INFO.*Activity:"
|
||||||
|
else
|
||||||
|
# Try common log file locations
|
||||||
|
echo "Systemd service not found. Trying common log file locations..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
LOG_FILES=(
|
||||||
|
"/tmp/mirrormatch-server.log"
|
||||||
|
"app.log"
|
||||||
|
"./app.log"
|
||||||
|
"/var/log/mirrormatch/app.log"
|
||||||
|
)
|
||||||
|
|
||||||
|
FOUND=false
|
||||||
|
for log in "${LOG_FILES[@]}"; do
|
||||||
|
if [ -f "$log" ]; then
|
||||||
|
echo "Found log file: $log"
|
||||||
|
echo ""
|
||||||
|
tail -f "$log" | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:|INFO.*Activity:"
|
||||||
|
FOUND=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$FOUND" = false ]; then
|
||||||
|
echo "❌ No log file found. Options:"
|
||||||
|
echo " 1. Specify log file: ./watch-activity.sh /path/to/logfile"
|
||||||
|
echo " 2. If using rebuild.sh, logs go to: /tmp/mirrormatch-server.log"
|
||||||
|
echo " 3. If using systemd, ensure app-backend service is running"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user