#!/bin/bash
# 查看同步订单日志的便捷脚本

cd "$(dirname "$0")"

echo "=== 同步订单日志查看工具 ==="
echo ""

# 检查日志文件是否存在
if [ ! -f "logs/api.log" ]; then
    echo "⚠️ 日志文件不存在: logs/api.log"
    echo "   请先启动 backend 服务"
    exit 1
fi

echo "日志文件位置:"
echo "  - Python 应用日志: backend/logs/api.log"
echo "  - Uvicorn 服务器日志: backend/logs/uvicorn.log"
echo ""

# 显示最近的同步日志
echo "=== 最近的同步订单日志（最后 50 行）==="
echo ""
tail -50 logs/api.log | grep -i "同步\|sync\|订单\|order" --color=always || echo "未找到同步相关日志"

echo ""
echo "=== 使用说明 ==="
echo ""
echo "实时查看同步日志："
echo "  tail -f logs/api.log | grep -i '同步\|sync'"
echo ""
echo "查看最近的同步日志："
echo "  tail -100 logs/api.log | grep -i '同步\|sync'"
echo ""
echo "查看特定时间的同步日志："
echo "  grep '2026-02-17 23:' logs/api.log | grep -i '同步\|sync'"
echo ""
echo "查看所有同步相关日志（包括详细信息）："
echo "  grep -i '同步\|sync\|订单\|order' logs/api.log | tail -100"
