Files
wx_service/internal/smoke/service/smoke_ai_debug_log.go
你çšnepiedg 12619aa4ab feat(database): add repairSmokeAIAdviceIndexes function and corresponding tests
- Implemented repairSmokeAIAdviceIndexes to manage the unique index for fa_smoke_ai_advice.
- Added unit tests for the new function to ensure correct index recreation and validation.
- Updated AutoMigrate to include the new index repair function.
2026-03-16 15:35:32 +08:00

49 lines
1.2 KiB
Go

package service
import (
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"time"
)
const smokeAIDebugLogDir = "/www/wwwroot/code/wx_service/runtime_logs"
func smokeAIDebugLogPath(now time.Time) string {
day := now.In(time.Local).Format("2006-01-02")
return filepath.Join(smokeAIDebugLogDir, fmt.Sprintf("smoke_ai_%s.log", day))
}
func appendSmokeAIDebugLog(scene string, payload map[string]interface{}) {
if payload == nil {
payload = map[string]interface{}{}
}
now := time.Now().In(time.Local)
payload["scene"] = scene
payload["ts"] = now.Format(time.RFC3339)
body, err := json.MarshalIndent(payload, "", " ")
if err != nil {
log.Printf("[smoke_ai_debug] marshal failed scene=%s err=%v", scene, err)
return
}
if err := os.MkdirAll(smokeAIDebugLogDir, 0o755); err != nil {
log.Printf("[smoke_ai_debug] mkdir failed scene=%s err=%v", scene, err)
return
}
f, err := os.OpenFile(smokeAIDebugLogPath(now), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
log.Printf("[smoke_ai_debug] open failed scene=%s err=%v", scene, err)
return
}
defer f.Close()
if _, err := f.Write(append(body, '\n', '\n')); err != nil {
log.Printf("[smoke_ai_debug] write failed scene=%s err=%v", scene, err)
}
}