Files
ai-team-dashboard/dashboard/test-logging-config.sh
fang 5f14174bb9 feat: 添加 Dashboard 完整日志监控系统 v1.1.0
 新增功能
- 完整的日志记录系统(6 种日志级别)
- 日志配置功能(可通过 config.json 控制)
- 性能监控装饰器和请求日志中间件
- 7 个管理工具脚本
- 完整的文档和使用指南

🛠️ 管理工具
- start-with-log.sh: 启动脚本(带日志)
- stop-dashboard.sh: 停止脚本
- view-logs.sh: 日志查看器
- monitor-logs.sh: 实时监控工具(支持多种过滤器)
- analyze-logs.sh: 日志分析工具(自动生成报告)
- demo-logging.sh: 功能演示脚本
- test-logging-config.sh: 配置测试工具

📊 日志特性
- 支持 INFO/SUCCESS/WARN/ERROR/DEBUG/PERF 6 种级别
- 自动记录启动过程、API 请求、性能统计
- 缓存命中情况追踪
- 分步性能监控
- 智能过滤器

⚙️ 配置功能
- 可控制是否启用日志(默认:true)
- 可设置日志级别(默认:INFO)
- 可控制文件/控制台输出
- 支持动态配置(重启生效)

📚 文档
- LOGGING_GUIDE.md: 完整使用指南
- LOGGING_CONFIG.md: 配置说明文档
- LOGGING_CONFIG_QUICK.md: 快速配置指南
- 多个中文说明文档

🔒 安全
- 添加 .gitignore 排除敏感信息
- config.json(含 Token)不提交
- 日志文件不提交
- 示例配置使用占位符

 测试
- 语法检查通过
- 功能完整性验证
- 配置控制测试通过
- 文档完整性检查

详见 CHANGELOG_v1.1.0.md

Made-with: Cursor
2026-03-11 11:37:35 +08:00

166 lines
5.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 测试不同的日志配置
# 展示各种配置的效果
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
clear
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${CYAN}🧪 Dashboard 日志配置测试${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# 备份当前配置
if [ -f "config.json" ]; then
echo -e "${YELLOW}备份当前配置...${NC}"
cp config.json config.json.backup
echo -e "${GREEN}✅ 已备份到 config.json.backup${NC}"
echo ""
fi
# 测试配置函数
test_config() {
local config_name=$1
local config_json=$2
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${CYAN}测试配置: $config_name${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "配置内容:"
echo "$config_json" | python3 -m json.tool 2>/dev/null || echo "$config_json"
echo ""
read -p "是否测试此配置?(y/N) " response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "跳过此配置"
echo ""
return
fi
# 更新 config.json 中的 logging 配置
if [ -f "config.json.backup" ]; then
cp config.json.backup config.json
fi
# 使用 Python 更新 JSON如果没有 Python 就手动提示)
if command -v python3 &> /dev/null; then
python3 << EOF
import json
with open('config.json', 'r') as f:
config = json.load(f)
config['dashboard']['logging'] = json.loads('''$config_json''')
with open('config.json', 'w') as f:
json.dump(config, f, indent=2, ensure_ascii=False)
EOF
echo -e "${GREEN}✅ 配置已更新${NC}"
else
echo -e "${YELLOW}⚠️ 请手动更新 config.json 中的 dashboard.logging 配置${NC}"
read -p "按 Enter 继续..." dummy
fi
# 重启服务
echo ""
echo "重启 Dashboard..."
./stop-dashboard.sh > /dev/null 2>&1
sleep 2
# 清空旧日志
> logs/dashboard.log 2>/dev/null
./start-with-log.sh
echo ""
echo "等待 3 秒..."
sleep 3
# 显示日志
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${CYAN}日志输出:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ -f "logs/dashboard.log" ]; then
head -30 logs/dashboard.log
else
echo "日志文件不存在"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
read -p "按 Enter 继续下一个测试..." dummy
echo ""
}
# 配置 1: 默认配置INFO 级别)
test_config "默认配置 (INFO 级别)" '{
"enabled": true,
"level": "INFO",
"file": true,
"console": true
}'
# 配置 2: DEBUG 级别
test_config "调试模式 (DEBUG 级别)" '{
"enabled": true,
"level": "DEBUG",
"file": true,
"console": true
}'
# 配置 3: 只记录警告和错误
test_config "只记录警告 (WARN 级别)" '{
"enabled": true,
"level": "WARN",
"file": true,
"console": true
}'
# 配置 4: 只记录错误
test_config "只记录错误 (ERROR 级别)" '{
"enabled": true,
"level": "ERROR",
"file": true,
"console": true
}'
# 配置 5: 关闭日志
test_config "关闭日志" '{
"enabled": false,
"level": "INFO",
"file": false,
"console": false
}'
# 恢复配置
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${GREEN}🎉 测试完成!${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ -f "config.json.backup" ]; then
read -p "是否恢复原始配置?(Y/n) " response
if [[ ! "$response" =~ ^[Nn]$ ]]; then
mv config.json.backup config.json
echo -e "${GREEN}✅ 已恢复原始配置${NC}"
echo ""
echo "重启 Dashboard 使配置生效:"
echo " ./stop-dashboard.sh && ./start-with-log.sh"
else
echo -e "${YELLOW}保留测试配置,备份文件: config.json.backup${NC}"
fi
fi
echo ""
echo "📚 更多信息:"
echo " cat LOGGING_CONFIG.md 查看完整配置说明"
echo " cat LOGGING_GUIDE.md 查看使用指南"
echo ""