Skip to content

Commit

Permalink
Improve output format
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchangelSDY committed Dec 9, 2022
1 parent 2308dca commit ab6917d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/checkers/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package checker

import (
"errors"
"log"

log "github.com/sirupsen/logrus"

"github.com/Azure/kdebug/pkg/base"
)
Expand All @@ -26,7 +27,7 @@ func Check(ctx *base.CheckContext, checkerNames []string) ([]*base.CheckResult,
for _, checker := range checkers {
r, err := checker.Check(ctx)
if err != nil {
log.Printf("Error in checker %s: %s", checker.Name(), err)
log.Warnf("Checker(%s): %s", checker.Name(), err)
}
results = append(results, r...)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/upgradeinspector/upgradeinspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func (t *UpgradeInspectTool) parseResult(result string) string {
if logNum == 0 {
sb.WriteString(color.GreenString("\nNo package upgrade log found\n"))
} else {
sb.WriteString(fmt.Sprintf("\n%-19s\t%-30s\t%-20s\t%-20s\n\n", columns[0], columns[1], columns[2], columns[3]))
sb.WriteString(fmt.Sprintf("\n%-19s\t%-40s\t%-30s\t%-30s\n\n", columns[0], columns[1], columns[2], columns[3]))
}

for i := 0; i < logNum && i < t.recordLimit; i++ {
strs := strings.Split(logs[i], " ")
sb.WriteString(fmt.Sprintf("%v-%v\t%-30s\t%-20s\t%-20s\n", strs[0], strs[1], strs[3], strs[4], strs[5]))
sb.WriteString(fmt.Sprintf("%v-%v\t%-40s\t%-30s\t%-30s\n", strs[0], strs[1], strs[3], strs[4], strs[5]))
}
if t.recordLimit < logNum {
sb.WriteString(color.YellowString("\n%v package(s) omitted\n", logNum-t.recordLimit))
Expand Down
6 changes: 3 additions & 3 deletions pkg/tools/upgradeinspector/upgradeinspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func TestUpgradeParser_Success(t *testing.T) {
logs := fmt.Sprintf("%s 17:12:13 upgrade libubsan1:amd64 12-20220319-1ubuntu1 12.1.0-2ubuntu1~22.04\n", dateStr) +
fmt.Sprintf("%s 17:12:13 upgrade gcc-12-base:amd64 12-20220319-1ubuntu1 12.1.0-2ubuntu1~22.04\n", dateStr)

expected := fmt.Sprintf("\n%-19s\t%-30s\t%-20s\t%-20s\n\n", "Timestamp", "Package", "OldVer", "NewVer") +
fmt.Sprintf("%v-%v\t%-30s\t%-20s\t%-20s\n", dateStr, "17:12:13", "libubsan1:amd64", "12-20220319-1ubuntu1", "12.1.0-2ubuntu1~22.04") +
fmt.Sprintf("%v-%v\t%-30s\t%-20s\t%-20s\n", dateStr, "17:12:13", "gcc-12-base:amd64", "12-20220319-1ubuntu1", "12.1.0-2ubuntu1~22.04")
expected := fmt.Sprintf("\n%-19s\t%-40s\t%-30s\t%-30s\n\n", "Timestamp", "Package", "OldVer", "NewVer") +
fmt.Sprintf("%v-%v\t%-40s\t%-30s\t%-30s\n", dateStr, "17:12:13", "libubsan1:amd64", "12-20220319-1ubuntu1", "12.1.0-2ubuntu1~22.04") +
fmt.Sprintf("%v-%v\t%-40s\t%-30s\t%-30s\n", dateStr, "17:12:13", "gcc-12-base:amd64", "12-20220319-1ubuntu1", "12.1.0-2ubuntu1~22.04")

output := upgradeInspectTool.parseResult(logs)

Expand Down

0 comments on commit ab6917d

Please sign in to comment.