package server import ( "log/slog" "net/http" "sort" ) func (s *Server) GetInstanceLogs(w http.ResponseWriter, r *http.Request, instanceId string) { slog.Debug("GetInstanceLogs endpoint called", "instanceId", instanceId) username, ok := s.usernameFromCtx(r) if !ok { http.Error(w, "Internal server error", http.StatusInternalServerError) return } if err := s.pagedb.ValidateInstanceOwner(r.Context(), instanceId, username); err != nil { slog.Debug("Instance ownership validation failed", "instanceId", instanceId, "error", err) http.Error(w, "Instance not found", http.StatusNotFound) return } entries := s.logs.List(instanceId) sort.Slice(entries, func(i, j int) bool { return entries[i].Timestamp.After(entries[j].Timestamp) }) slog.Debug("Returning instance logs", "instanceId", instanceId, "count", len(entries)) writeJSONResponse(w, http.StatusOK, entries) }