Skip to content

Commit

Permalink
change info message logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsgstrabo committed Nov 29, 2023
1 parent be1c732 commit a98d5d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions cmd/logsPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/settings"
"github.com/equinor/radix-cli/pkg/utils/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -119,7 +120,7 @@ func getLogsJob(cmd *cobra.Command, apiClient *apiclient.Radixapi, appName, jobN

jobStepLog, err := apiClient.PipelineJob.GetPipelineJobStepLogs(stepLogsParams, nil)
if err != nil {
log.Print(cmd, "radix-cli", fmt.Sprintf("Failed to get pipeline job logs. %v", err), log.Red)
logrus.Infof("Failed to get pipeline job logs. %v", err)
break
}
logLines := strings.Split(strings.Replace(jobStepLog.Payload, "\r\n", "\n", -1), "\n")
Expand Down Expand Up @@ -154,10 +155,10 @@ func getLogsJob(cmd *cobra.Command, apiClient *apiclient.Radixapi, appName, jobN
getLogAttempts--
if getLogAttempts > 0 {
getLogAwaitingTime := int(time.Since(getLogStartTime))
log.Print(cmd, "radix-cli", fmt.Sprintf("Nothing logged the last %d seconds. Job summary: %v. Status: %s. Contihue waiting", getLogAwaitingTime, jobSummary, jobSummary.Status), log.GetColor(0))
logrus.Infof("Nothing logged the last %d seconds. Job summary: %v. Status: %s. Contihue waiting", getLogAwaitingTime, jobSummary, jobSummary.Status)
break
}
log.Print(cmd, "radix-cli", fmt.Sprintf("Nothing logged the last %s. Job summary: %v. Status: %s. Timeout", settings.DeltaTimeout, jobSummary, jobSummary.Status), log.GetColor(0))
logrus.Infof("Nothing logged the last %s. Job summary: %v. Status: %s. Timeout", settings.DeltaTimeout, jobSummary, jobSummary.Status)
return nil
}
}
Expand All @@ -168,12 +169,12 @@ func isCompletedJob(status string) bool {
}

func errorAndLogJobStatus(status string, cmd *cobra.Command) error {
msg := fmt.Sprintf("job completed with status %s", status)
fmt.Fprintln(cmd.OutOrStdout())
msg := fmt.Sprintf("job is completed with status %s", status)
if status == jobStatusFailed {
fmt.Fprintln(cmd.OutOrStdout())
return errors.New(msg)
}
log.Print(cmd, "radix-cli", msg, log.Red)
logrus.Info(msg)
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/log/log_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func GetColor(num int) func(a ...interface{}) string {
func PrintLines(cmd *cobra.Command, name string, previousLogLines, logLines []string, color func(a ...interface{}) string) {
for _, logLine := range logLines {
if !logged(logLine, previousLogLines) {
Print(cmd, name, logLine, color)
print(cmd, name, logLine, color)
}
}
}
Expand All @@ -42,7 +42,7 @@ func logged(logLine string, previousLogLines []string) bool {
return false
}

// Print Output string to standard output
func Print(cmd *cobra.Command, name, logLine string, color func(a ...interface{}) string) {
// print Output string to standard output
func print(cmd *cobra.Command, name, logLine string, color func(a ...interface{}) string) {
fmt.Fprintf(cmd.OutOrStdout(), "\r\n[%s] : %s", color(name), color(logLine))
}

0 comments on commit a98d5d5

Please sign in to comment.