87214b9441
Phase 1 (基础设施): - ThinkChain 思考链连续性 + 差异化思考提示词 (persistent) - AutonomousToolPolicy 工具安全策略 (safe/unsafe/conditional) - MessageScheduler 自适应消息节奏 (Idle/Available/Busy) - SessionEnrichmentStore 渐进式上下文丰富 (5层) - ConversationBus 事件总线 + ResponseCache (dedup) - pkg/logger 统一日志 + 所有 handler 替换 fmt.Printf - NPE 守卫/链路优化/数据库表修复/Go workspace Phase 2 (人格交互): - EmotionState/EmotionTracker 情感状态机 (5种心情, 情绪衰减) - ProactiveGuard 主动消息多维决策 (静默时段/紧急度/频率/校验) - Gateway↔ai-core 在线状态感知链路 (presence notification) - 离线思考频率控制 + 重连问候 + 离线消息排队 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 lines
684 B
Go
37 lines
684 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/yourname/cyrene-ai/pkg/logger"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RequestLogging 请求日志中间件
|
|
func RequestLogging() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
start := time.Now()
|
|
|
|
// 处理请求
|
|
c.Next()
|
|
|
|
// 记录日志
|
|
duration := time.Since(start)
|
|
statusCode := c.Writer.Status()
|
|
method := c.Request.Method
|
|
path := c.Request.URL.Path
|
|
clientIP := c.ClientIP()
|
|
|
|
logLevel := "[INFO]"
|
|
if statusCode >= 500 {
|
|
logLevel = "[ERROR]"
|
|
} else if statusCode >= 400 {
|
|
logLevel = "[WARN]"
|
|
}
|
|
|
|
logger.Printf("%s %s %s %d %v %s",
|
|
logLevel, method, path, statusCode, duration, clientIP,
|
|
)
|
|
}
|
|
}
|