refactor: use standard logger instead of logrus

This commit is contained in:
Lukas Zapletal 2025-04-29 15:17:22 +02:00 committed by Achilleas Koutsou
parent 48cd004bed
commit 392a04fd12
9 changed files with 152 additions and 29 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"
@ -14,7 +15,6 @@ import (
"github.com/cheggaaa/pb/v3"
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/osbuild"
@ -241,7 +241,7 @@ func (b *terminalProgressBar) Stop() {
// I cannot think of how this could happen, i.e. why
// closing would not work but lets be conservative -
// without a timeout we hang here forever
logrus.Warnf("no progress channel shutdown after 1sec")
log.Printf("WARNING: no progress channel shutdown after 1sec")
}
b.shutdownCh = nil
// This should never happen but be paranoid, this should
@ -479,7 +479,7 @@ func runOSBuildWithProgress(pb ProgressBar, manifest []byte, exports []string, o
i := 0
for p := st.Progress; p != nil; p = p.SubProgress {
if err := pb.SetProgress(i, p.Message, p.Done, p.Total); err != nil {
logrus.Warnf("cannot set progress: %v", err)
log.Printf("WARNING: cannot set progress: %v", err)
}
i++
}

View file

@ -2,6 +2,7 @@ package setup
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
@ -10,8 +11,6 @@ import (
"golang.org/x/sys/unix"
"github.com/sirupsen/logrus"
"github.com/osbuild/image-builder-cli/pkg/podmanutil"
"github.com/osbuild/image-builder-cli/pkg/util"
)
@ -136,7 +135,7 @@ func validateCanRunTargetArch(targetArch string) error {
// we could error here but in principle with a working qemu-user
// any arch should work so let's just warn. the common case
// (arm64/amd64) is covered properly
logrus.Warningf("cannot check architecture support for %v: no canary binary found", targetArch)
log.Printf("WARNING: cannot check architecture support for %v: no canary binary found", targetArch)
return nil
}
output, err := exec.Command(canaryCmd).CombinedOutput()

View file

@ -3,12 +3,12 @@ package setup_test
import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/osbuild/image-builder-cli/pkg/setup"
@ -23,11 +23,13 @@ func TestValidateCanRunTargetArchTrivial(t *testing.T) {
func TestValidateCanRunTargetArchUnsupportedCanary(t *testing.T) {
var logbuf bytes.Buffer
logrus.SetOutput(&logbuf)
ow := log.Writer()
log.SetOutput(&logbuf)
defer log.SetOutput(ow)
err := setup.ValidateCanRunTargetArch("unsupported-arch")
assert.NoError(t, err)
assert.Contains(t, logbuf.String(), `level=warning msg="cannot check architecture support for unsupported-arch: no canary binary found"`)
assert.Contains(t, logbuf.String(), `cannot check architecture support for unsupported-arch: no canary binary found`)
}
func makeFakeBinary(t *testing.T, binary, content string) {
@ -43,7 +45,9 @@ func makeFakeCanary(t *testing.T, content string) {
func TestValidateCanRunTargetArchHappy(t *testing.T) {
var logbuf bytes.Buffer
logrus.SetOutput(&logbuf)
ow := log.Writer()
log.SetOutput(&logbuf)
defer log.SetOutput(ow)
makeFakeCanary(t, "#!/bin/sh\necho ok")

View file

@ -6,7 +6,7 @@ import (
"os/exec"
"strings"
"github.com/sirupsen/logrus"
"github.com/osbuild/image-builder-cli/internal/olog"
)
// IsMountpoint checks if the target path is a mount point
@ -17,7 +17,7 @@ func IsMountpoint(path string) bool {
// Synchronously invoke a command, propagating stdout and stderr
// to the current process's stdout and stderr
func RunCmdSync(cmdName string, args ...string) error {
logrus.Debugf("Running: %s %s", cmdName, strings.Join(args, " "))
olog.Printf("Running: %s %s", cmdName, strings.Join(args, " "))
cmd := exec.Command(cmdName, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr