Files
django-vue3-admin/scripts/view-logs.sh
T
lewis_yan f6313a93ce feat: add cross-platform service management scripts
Add comprehensive scripts for managing PIS project services:
- start-backend.ps1/.sh: Start Django backend with uvicorn/gunicorn
- start-frontend.ps1/.sh: Start Vue frontend dev server
- start-celery.ps1/.sh: Start Celery worker and beat
- stop-all.ps1/.sh: Stop all services gracefully
- stop-celery.ps1/.sh: Stop Celery services only
- view-logs.ps1/.sh: View and tail log files
- check-status.ps1/.sh: Check service status and ports

Cross-platform support:
- Windows PowerShell scripts with English output (UTF-8 safe)
- Unix/Linux/macOS Bash scripts with Chinese output
- WMI queries for PowerShell 5.1 compatibility
- Unified Makefile and make.ps1 orchestrators

Also add scripts-documentation.md with comprehensive usage guide.
2026-04-01 19:11:45 +08:00

62 lines
2.0 KiB
Bash

#!/bin/bash
# ============================================================
# View Logs
# 使用方法: ./view-logs.sh [backend|frontend|celery|all]
# ============================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
BACKEND_DIR="$PROJECT_ROOT/backend"
LOG_DIR="$BACKEND_DIR/logs"
TARGET=${1:-all}
# 确保日志目录存在
mkdir -p "$LOG_DIR"
# 创建空的日志文件(如果不存在)
touch "$LOG_DIR/backend.log" 2>/dev/null || true
touch "$LOG_DIR/frontend.log" 2>/dev/null || true
touch "$LOG_DIR/celery_worker.log" 2>/dev/null || true
touch "$LOG_DIR/celery_beat.log" 2>/dev/null || true
case "$TARGET" in
backend)
echo "查看后端日志: $LOG_DIR/backend.log"
tail -f "$LOG_DIR/backend.log"
;;
frontend)
echo "查看前端日志: $LOG_DIR/frontend.log"
tail -f "$LOG_DIR/frontend.log"
;;
celery)
echo "查看 Celery 日志..."
echo "=== Worker ==="
tail -f "$LOG_DIR/celery_worker.log" &
echo "=== Beat ==="
tail -f "$LOG_DIR/celery_beat.log"
;;
all)
echo "查看所有日志 (Ctrl+C 退出)..."
echo ""
echo "=== 后端日志 ==="
tail -n 20 "$LOG_DIR/backend.log" 2>/dev/null || echo "(空)"
echo ""
echo "=== 前端日志 ==="
tail -n 20 "$LOG_DIR/frontend.log" 2>/dev/null || echo "(空)"
echo ""
echo "=== Celery Worker 日志 ==="
tail -n 20 "$LOG_DIR/celery_worker.log" 2>/dev/null || echo "(空)"
echo ""
echo "=== Celery Beat 日志 ==="
tail -n 20 "$LOG_DIR/celery_beat.log" 2>/dev/null || echo "(空)"
echo ""
echo "--- 实时监控所有日志 (Ctrl+C 退出) ---"
tail -f "$LOG_DIR/backend.log" "$LOG_DIR/frontend.log" "$LOG_DIR/celery_worker.log" "$LOG_DIR/celery_beat.log"
;;
*)
echo "用法: $0 [backend|frontend|celery|all]"
exit 1
;;
esac