Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 15 additions & 11 deletions cmd/logs_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ var logsQueryCmd = &cobra.Command{
req := client.NewRequest(`
query FetchLogs($request: FetchLogRequest!) {
logs_list(request: $request) {
timestamp
severity
message
labels
logs {
timestamp
severity
message
labels
}
}
Comment thread
blue4209211 marked this conversation as resolved.
}
`)
Expand All @@ -70,25 +72,27 @@ var logsQueryCmd = &cobra.Command{
req.Var("request", requestVars)

var respData struct {
LogsList []struct {
Timestamp string `json:"timestamp"`
Severity string `json:"severity"`
Message string `json:"message"`
Labels json.RawMessage `json:"labels"`
LogsList struct {
Logs []struct {
Timestamp string `json:"timestamp"`
Severity string `json:"severity"`
Message string `json:"message"`
Labels json.RawMessage `json:"labels"`
} `json:"logs"`
} `json:"logs_list"`
}

if err := graphqlClient.Run(context.Background(), req, &respData); err != nil {
return err
}

if len(respData.LogsList) == 0 {
if len(respData.LogsList.Logs) == 0 {
fmt.Println("No logs found.")
return nil
}

table := format.TabularData{
Data: respData.LogsList,
Data: respData.LogsList.Logs,
Fields: []format.TableField{
{Header: "Timestamp", Field: "Timestamp"},
{Header: "Severity", Field: "Severity"},
Expand Down
14 changes: 8 additions & 6 deletions cmd/logs_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (

func TestLogsQuery_Unit(t *testing.T) {
mockData := map[string]any{
"logs_list": []map[string]any{
{
"timestamp": "2025-10-15T10:00:00Z",
"severity": "info",
"message": "Log message 1",
"labels": "{}",
"logs_list": map[string]any{
"logs": []map[string]any{
{
"timestamp": "2025-10-15T10:00:00Z",
"severity": "info",
"message": "Log message 1",
"labels": "{}",
},
},
},
Comment thread
blue4209211 marked this conversation as resolved.
}
Expand Down