Skip to content

Commit

Permalink
Display stream in logs, closes #192
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Mar 4, 2024
1 parent 44f7b56 commit fa682e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Display date in `koyeb service logs` and `koyeb instance logs`
- https://github.com/koyeb/koyeb-cli/issues/190
* Display the log stream in `koyeb service logs` and `koyeb instance logs`
- https://github.com/koyeb/koyeb-cli/issues/192

## v3.8.1

Expand Down
29 changes: 22 additions & 7 deletions pkg/koyeb/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,26 @@ type LogLine struct {
}

type LogLineResult struct {
CreatedAt string `json:"created_at"`
Msg string `json:"msg"`
CreatedAt string `json:"created_at"`
Msg string `json:"msg"`
Labels LogLineResultLabels `json:"labels"`
}

type LogLineResultLabels struct {
Type string `json:"type"`
Stream string `json:"stream"`
OrganizationID string `json:"organization_id"`
AppID string `json:"app_id"`
ServiceID string `json:"service_id"`
InstanceID string `json:"instance_id"`
}

// WatchLogsEntry is an entry returned by WatchLogsQuery.Execute()
type WatchLogsEntry struct {
Date time.Time
Msg string
Err error
Date time.Time
Stream string
Msg string
Err error
}

// ParseTime parses a time string contained in the field result.created_at of
Expand Down Expand Up @@ -152,7 +163,11 @@ func (query *WatchLogsQuery) Execute() (chan WatchLogsEntry, error) {
Solution: "Try again in a few seconds",
}}
} else {
logs <- WatchLogsEntry{Msg: msg.Result.Msg, Date: query.ParseTime(msg.Result.CreatedAt)}
logs <- WatchLogsEntry{
Stream: msg.Result.Labels.Stream,
Msg: msg.Result.Msg,
Date: query.ParseTime(msg.Result.CreatedAt),
}
}
}
}()
Expand Down Expand Up @@ -206,7 +221,7 @@ func (query *WatchLogsQuery) PrintAll() error {
layout := "2006-01-02 15:04:05"
date := log.Date.Format(layout)
zone, _ := log.Date.Zone()
fmt.Printf("[%s %s] %s\n", date, zone, log.Msg)
fmt.Printf("[%s %s] %6s - %s\n", date, zone, log.Stream, log.Msg)
}
return nil
}

0 comments on commit fa682e6

Please sign in to comment.