mirror of
https://github.com/kairos-io/immucore.git
synced 2025-08-01 06:27:42 +00:00
Drop logrus and use zerolog for yip (#141)
This commit is contained in:
parent
9d3a6aaae1
commit
471c9782da
4
go.mod
4
go.mod
@ -18,7 +18,6 @@ require (
|
|||||||
github.com/onsi/ginkgo/v2 v2.11.0
|
github.com/onsi/ginkgo/v2 v2.11.0
|
||||||
github.com/onsi/gomega v1.27.10
|
github.com/onsi/gomega v1.27.10
|
||||||
github.com/rs/zerolog v1.30.0
|
github.com/rs/zerolog v1.30.0
|
||||||
github.com/sirupsen/logrus v1.9.0
|
|
||||||
github.com/spectrocloud-labs/herd v0.4.2
|
github.com/spectrocloud-labs/herd v0.4.2
|
||||||
github.com/twpayne/go-vfs v1.7.2
|
github.com/twpayne/go-vfs v1.7.2
|
||||||
github.com/urfave/cli/v2 v2.25.7
|
github.com/urfave/cli/v2 v2.25.7
|
||||||
@ -82,7 +81,6 @@ require (
|
|||||||
github.com/itchyny/timefmt-go v0.1.5 // indirect
|
github.com/itchyny/timefmt-go v0.1.5 // indirect
|
||||||
github.com/jaypipes/pcidb v1.0.0 // indirect
|
github.com/jaypipes/pcidb v1.0.0 // indirect
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/kairos-io/kairos v1.24.3-56.0.20230329142538-b6ae4b58c07d // indirect
|
|
||||||
github.com/kendru/darwin/go/depgraph v0.0.0-20221105232959-877d6a81060c // indirect
|
github.com/kendru/darwin/go/depgraph v0.0.0-20221105232959-877d6a81060c // indirect
|
||||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||||
github.com/klauspost/compress v1.16.5 // indirect
|
github.com/klauspost/compress v1.16.5 // indirect
|
||||||
@ -98,6 +96,7 @@ require (
|
|||||||
github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49 // indirect
|
github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49 // indirect
|
||||||
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 // indirect
|
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 // indirect
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||||
|
github.com/nxadm/tail v1.4.8 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
|
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
|
||||||
github.com/packethost/packngo v0.29.0 // indirect
|
github.com/packethost/packngo v0.29.0 // indirect
|
||||||
@ -115,6 +114,7 @@ require (
|
|||||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
|
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
|
||||||
github.com/sergi/go-diff v1.3.1 // indirect
|
github.com/sergi/go-diff v1.3.1 // indirect
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||||
github.com/spf13/cast v1.5.0 // indirect
|
github.com/spf13/cast v1.5.0 // indirect
|
||||||
github.com/tredoe/osutil/v2 v2.0.0-rc.16 // indirect
|
github.com/tredoe/osutil/v2 v2.0.0-rc.16 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.11 // indirect
|
github.com/ulikunitz/xz v0.5.11 // indirect
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
"github.com/mudler/yip/pkg/logger"
|
"github.com/mudler/yip/pkg/logger"
|
||||||
"github.com/mudler/yip/pkg/plugins"
|
"github.com/mudler/yip/pkg/plugins"
|
||||||
"github.com/mudler/yip/pkg/schema"
|
"github.com/mudler/yip/pkg/schema"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/rs/zerolog"
|
||||||
"github.com/twpayne/go-vfs"
|
"github.com/twpayne/go-vfs"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -54,14 +55,18 @@ func RunStage(stage string) (bytes.Buffer, error) {
|
|||||||
var allErrors, err error
|
var allErrors, err error
|
||||||
var cmdLineYipURI string
|
var cmdLineYipURI string
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
log := logrus.New()
|
var level zerolog.Level
|
||||||
log.SetOutput(&buffer)
|
|
||||||
// Set debug logger
|
// Specific log here so it writes to a buffer and we can return that as output
|
||||||
|
level = zerolog.InfoLevel
|
||||||
|
// Set debug level
|
||||||
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||||
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
||||||
if debug || debugFromEnv {
|
if debug || debugFromEnv {
|
||||||
log.SetLevel(logrus.DebugLevel)
|
level = zerolog.DebugLevel
|
||||||
}
|
}
|
||||||
|
log := MiddleLog{zerolog.New(bufio.NewWriter(&buffer)).With().Logger().Level(level)}
|
||||||
|
// Set debug logger
|
||||||
yip := NewYipExecutor(log)
|
yip := NewYipExecutor(log)
|
||||||
c := ImmucoreConsole{}
|
c := ImmucoreConsole{}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -18,6 +19,7 @@ func CloseLogFiles() {
|
|||||||
|
|
||||||
func SetLogger() {
|
func SetLogger() {
|
||||||
var loggers []io.Writer
|
var loggers []io.Writer
|
||||||
|
var level zerolog.Level
|
||||||
_ = os.MkdirAll(constants.LogDir, os.ModeDir|os.ModePerm)
|
_ = os.MkdirAll(constants.LogDir, os.ModeDir|os.ModePerm)
|
||||||
logFile, err := os.Create(filepath.Join(constants.LogDir, "immucore.log"))
|
logFile, err := os.Create(filepath.Join(constants.LogDir, "immucore.log"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -27,12 +29,60 @@ func SetLogger() {
|
|||||||
loggers = append(loggers, zerolog.ConsoleWriter{Out: os.Stderr})
|
loggers = append(loggers, zerolog.ConsoleWriter{Out: os.Stderr})
|
||||||
|
|
||||||
multi := zerolog.MultiLevelWriter(loggers...)
|
multi := zerolog.MultiLevelWriter(loggers...)
|
||||||
Log = zerolog.New(multi).With().Logger().Level(zerolog.InfoLevel)
|
level = zerolog.InfoLevel
|
||||||
|
// Set debug level
|
||||||
// Set debug logger
|
|
||||||
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||||
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
||||||
if debug || debugFromEnv {
|
if debug || debugFromEnv {
|
||||||
Log = zerolog.New(multi).With().Caller().Logger().Level(zerolog.DebugLevel)
|
level = zerolog.DebugLevel
|
||||||
}
|
}
|
||||||
|
Log = zerolog.New(multi).With().Logger().Level(level)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MiddleLog implements the bridge between zerolog and the logger.Interface that yip needs.
|
||||||
|
type MiddleLog struct {
|
||||||
|
zerolog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m MiddleLog) Infof(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Info().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Info(args ...interface{}) {
|
||||||
|
m.Logger.Info().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Warnf(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Warn().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Warn(args ...interface{}) {
|
||||||
|
m.Logger.Warn().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Debugf(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Debug().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Debug(args ...interface{}) {
|
||||||
|
m.Logger.Debug().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Errorf(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Error().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Error(args ...interface{}) {
|
||||||
|
m.Logger.Error().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Fatalf(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Fatal().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Fatal(args ...interface{}) {
|
||||||
|
m.Logger.Fatal().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Panicf(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Panic().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Panic(args ...interface{}) {
|
||||||
|
m.Logger.Panic().Msg(fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Tracef(tpl string, args ...interface{}) {
|
||||||
|
m.Logger.Trace().Msg(fmt.Sprintf(tpl, args...))
|
||||||
|
}
|
||||||
|
func (m MiddleLog) Trace(args ...interface{}) {
|
||||||
|
m.Logger.Trace().Msg(fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user