Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cmd/logs_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,12 @@ func runLogsSearch(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to search logs: %w", err)
}

// Collect all logs from all pages
// Collect logs up to the requested limit
allLogs := resp.GetData()
pageCount := 1

// Follow pagination if there's more data
for {
// Follow pagination until we hit the limit or run out of pages
for logsLimit > 0 && len(allLogs) < logsLimit {
meta, ok := resp.GetMetaOk()
if !ok || meta == nil {
break
Expand All @@ -724,12 +724,18 @@ func runLogsSearch(cmd *cobra.Command, args []string) error {
break
}

// Fetch next page
remaining := logsLimit - len(allLogs)
if remaining <= 0 {
break
}
Comment on lines +728 to +730
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check for remaining <= 0 is redundant and unreachable. The loop condition at line 713 already ensures that len(allLogs) < logsLimit, which means remaining will always be greater than 0 when we reach this point. This code block can be removed.

Suggested change
if remaining <= 0 {
break
}

Copilot uses AI. Check for mistakes.
remainingLimit := int32(remaining)
if remainingLimit < limit {
body.Page.Limit = &remainingLimit
}
body.Page.Cursor = cursor
opts.Body = &body
resp, r, err = api.ListLogs(client.Context(), opts)
if err != nil {
// Return what we have so far with a warning
printOutput("Warning: Failed to fetch page %d: %v\n", pageCount+1, err)
break
}
Expand All @@ -738,6 +744,10 @@ func runLogsSearch(cmd *cobra.Command, args []string) error {
pageCount++
}

if logsLimit > 0 && len(allLogs) > logsLimit {
allLogs = allLogs[:logsLimit]
}

// Show helpful message if no logs found
if len(allLogs) == 0 {
printOutput("No logs found matching your query.\n\n")
Expand All @@ -749,10 +759,8 @@ func runLogsSearch(cmd *cobra.Command, args []string) error {
return nil
}

// Build response with all collected logs
finalResp := resp
if pageCount > 1 {
// Update data with all collected logs
finalResp.SetData(allLogs)
printOutput("Fetched %d logs across %d pages\n\n", len(allLogs), pageCount)
}
Expand Down
Loading