fix: restore operation logging hook

This commit is contained in:
OpenClaw Agent
2026-09-21 16:14:46 +08:00
parent f252a7a195
commit 5b2110eb98
+20
View File
@@ -85,6 +85,26 @@ func account(r *http.Request, s *Server) *auth.Account {
return s.Auth.Guest return s.Auth.Guest
} }
func (s *Server) logOp(r *http.Request, action string) {
if s.Log == nil {
return
}
a := account(r, s)
user := ""
if a != nil {
user = a.Username
}
_ = s.Log.Write(clientIPString(r), user, action)
}
func clientIPString(r *http.Request) string {
ip := clientIP(r)
if ip == nil {
return "-"
}
return ip.String()
}
func writeJSON(w http.ResponseWriter, v any) { func writeJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(v) json.NewEncoder(w).Encode(v)