mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Improve logging (#3788)
This commit is contained in:
parent
1fde2ce677
commit
a5fcc7517b
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||
@ -92,15 +93,28 @@ func PrintLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, c
|
||||
return entity.ToLogOverview.Results[i].Index < entity.ToLogOverview.Results[j].Index
|
||||
})
|
||||
|
||||
// Get Lengths
|
||||
phaseLength := 22 // minimum default length
|
||||
for _, logEntry := range entity.ToLogOverview.Results {
|
||||
if l := len(logEntry.Name); l > phaseLength {
|
||||
phaseLength = l
|
||||
}
|
||||
}
|
||||
statusLength := 10
|
||||
timestampLength := 29
|
||||
|
||||
// Dashed Line Length
|
||||
lineLength := 10 + phaseLength + statusLength + timestampLength
|
||||
|
||||
// Print Overview
|
||||
log.Entry().Infof("\n")
|
||||
log.Entry().Infof("-----------------------------------------------------------------------")
|
||||
log.Entry().Infof("| %-22s | %10s | %-29s |", "Phase", "Status", "Timestamp")
|
||||
log.Entry().Infof("-----------------------------------------------------------------------")
|
||||
dashedLine(lineLength)
|
||||
log.Entry().Infof("| %-"+fmt.Sprint(phaseLength)+"s | %"+fmt.Sprint(statusLength)+"s | %-"+fmt.Sprint(timestampLength)+"s |", "Phase", "Status", "Timestamp")
|
||||
dashedLine(lineLength)
|
||||
for _, logEntry := range entity.ToLogOverview.Results {
|
||||
log.Entry().Infof("| %-22s | %10s | %-29s |", logEntry.Name, logEntry.Status, ConvertTime(logEntry.Timestamp))
|
||||
log.Entry().Infof("| %-"+fmt.Sprint(phaseLength)+"s | %"+fmt.Sprint(statusLength)+"s | %-"+fmt.Sprint(timestampLength)+"s |", logEntry.Name, logEntry.Status, ConvertTime(logEntry.Timestamp))
|
||||
}
|
||||
log.Entry().Infof("-----------------------------------------------------------------------")
|
||||
dashedLine(lineLength)
|
||||
|
||||
// Print Details
|
||||
for _, logEntryForDetails := range entity.ToLogOverview.Results {
|
||||
@ -111,6 +125,10 @@ func PrintLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, c
|
||||
return
|
||||
}
|
||||
|
||||
func dashedLine(i int) {
|
||||
log.Entry().Infof(strings.Repeat("-", i))
|
||||
}
|
||||
|
||||
func printLog(logEntry LogResultsV2) {
|
||||
|
||||
sort.SliceStable(logEntry.ToLogProtocol.Results, func(i, j int) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user