diff --git a/CHANGES.md b/CHANGES.md index 7d143c5d..3e3e0819 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ * Add warning when accessing logs of a deployment with skipped build. - https://github.com/koyeb/koyeb-cli/pull/201 +* Add instance ID to `koyeb service logs`, `koyeb deployment logs` and `koyeb instance logs` + - https://github.com/koyeb/koyeb-cli/pull/202 ## v3.10.0 diff --git a/pkg/koyeb/deployments_logs.go b/pkg/koyeb/deployments_logs.go index a7743f76..1a10abdb 100644 --- a/pkg/koyeb/deployments_logs.go +++ b/pkg/koyeb/deployments_logs.go @@ -27,6 +27,7 @@ func (h *DeploymentHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []str "", deploymentDetail.Deployment.GetId(), "", + GetBoolFlags(cmd, "full"), ) if err != nil { return err diff --git a/pkg/koyeb/instances_logs.go b/pkg/koyeb/instances_logs.go index 9b6c75ff..f8a38737 100644 --- a/pkg/koyeb/instances_logs.go +++ b/pkg/koyeb/instances_logs.go @@ -26,6 +26,7 @@ func (h *InstanceHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []strin "", "", instanceDetail.Instance.GetId(), + GetBoolFlags(cmd, "full"), ) if err != nil { return err diff --git a/pkg/koyeb/logs.go b/pkg/koyeb/logs.go index 1bfc5447..69644f27 100644 --- a/pkg/koyeb/logs.go +++ b/pkg/koyeb/logs.go @@ -8,6 +8,7 @@ import ( "github.com/gorilla/websocket" "github.com/koyeb/koyeb-cli/pkg/koyeb/errors" + "github.com/koyeb/koyeb-cli/pkg/koyeb/renderer" ) type LogsAPIClient struct { @@ -48,16 +49,18 @@ type WatchLogsQuery struct { instanceId string conn *websocket.Conn ticker *time.Ticker + full bool // Whether to display full IDs } func (client *LogsAPIClient) NewWatchLogsQuery( - logType string, serviceId string, deploymentId string, instanceId string, + logType string, serviceId string, deploymentId string, instanceId string, full bool, ) (*WatchLogsQuery, error) { query := &WatchLogsQuery{ client: client, serviceId: serviceId, deploymentId: deploymentId, instanceId: instanceId, + full: full, } switch logType { case "build", "runtime", "": @@ -102,6 +105,7 @@ type WatchLogsEntry struct { Stream string Msg string Err error + Labels LogLineResultLabels } // ParseTime parses a time string contained in the field result.created_at of @@ -167,6 +171,7 @@ func (query *WatchLogsQuery) Execute() (chan WatchLogsEntry, error) { Stream: msg.Result.Labels.Stream, Msg: msg.Result.Msg, Date: query.ParseTime(msg.Result.CreatedAt), + Labels: msg.Result.Labels, } } } @@ -221,7 +226,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] %6s - %s\n", date, zone, log.Stream, log.Msg) + fmt.Printf("[%s %s] %s %6s - %s\n", date, zone, renderer.FormatID(log.Labels.InstanceID, query.full), log.Stream, log.Msg) } return nil } diff --git a/pkg/koyeb/services_logs.go b/pkg/koyeb/services_logs.go index 587d9b39..5e20792b 100644 --- a/pkg/koyeb/services_logs.go +++ b/pkg/koyeb/services_logs.go @@ -95,6 +95,7 @@ func (h *ServiceHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []string serviceId, deploymentId, instanceId, + GetBoolFlags(cmd, "full"), ) if err != nil { return err