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:
ilia 2026-01-04 21:44:48 -05:00
parent 1e7a47ad31
commit f4155cf820
3 changed files with 77 additions and 23 deletions

View File

@ -32,6 +32,18 @@ tail -f /tmp/mirrormatch-server.log
### Development 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
If you prefer to run commands manually:

View File

@ -6,11 +6,16 @@
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
MODE=${1:-prod}
echo "========================================="
echo "MirrorMatch - Clean Rebuild & Start"
echo "Mode: ${MODE}"
echo "Working directory: $SCRIPT_DIR"
echo "========================================="
# Step 1: Kill everything
@ -33,7 +38,6 @@ echo "✓ Ports freed"
# Step 3: Clean build artifacts
echo ""
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
echo "✓ Build artifacts cleaned"
@ -59,19 +63,21 @@ if [ "$MODE" = "dev" ]; then
unset AUTH_TRUST_HOST
npm run dev
else
LOG_FILE="${LOG_FILE:-/tmp/mirrormatch-server.log}"
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 ""
export NODE_ENV=production
unset AUTH_TRUST_HOST
npm run start > /tmp/mirrormatch-server.log 2>&1 &
npm run start > "$LOG_FILE" 2>&1 &
echo "Server PID: $!"
echo "Log file: $LOG_FILE"
echo ""
sleep 3
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"
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

74
watch-activity.sh Normal file → Executable file
View File

@ -1,29 +1,65 @@
#!/bin/bash
# Watch user activity logs in real-time
#
# This script monitors systemd journal logs for MirrorMatch activity.
# It filters for activity-related log entries including page visits, photo uploads, and guess submissions.
# This script monitors logs for MirrorMatch activity.
# 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:
# - Systemd/journalctl (Linux systems with systemd)
# - Appropriate permissions (may require sudo)
# - Application running as a systemd service named "app-backend"
#
# For local development without systemd:
# - 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
# For local development:
# - If running via rebuild.sh: ./watch-activity.sh /tmp/mirrormatch-server.log
# - If running via npm run dev: ./watch-activity.sh app.log (if you redirect output)
# - If running as systemd service: ./watch-activity.sh (uses journalctl)
LOG_FILE="${1:-}"
echo "Watching user activity logs..."
echo "Press Ctrl+C to stop"
echo ""
# Watch for activity logs (ACTIVITY, PHOTO_UPLOAD, GUESS_SUBMIT)
# These patterns match the activity log format from lib/activity-log.ts
sudo journalctl -u app-backend -f | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:"
if [ -n "$LOG_FILE" ]; then
# Watch log file
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