Skip to content

Commit

Permalink
Merge branch 'main' into mojtaba/reduce-bittwister-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MSevey authored Jun 6, 2024
2 parents 8517339 + 25709d1 commit 7de0ce5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/celestiaorg/knuu

go 1.22.3
go 1.22.4

require (
github.com/celestiaorg/bittwister v0.0.0-20231213180407-65cdbaf5b8c7
github.com/docker/docker v26.1.3+incompatible
github.com/docker/docker v26.1.4+incompatible
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/minio/minio-go/v7 v7.0.70
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v26.1.3+incompatible h1:lLCzRbrVZrljpVNobJu1J2FHk8V0s4BawoZippkc+xo=
github.com/docker/docker v26.1.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.1.4+incompatible h1:vuTpXDuoga+Z38m1OZHzl7NKisKWaWlhjQk7IDPSLsU=
github.com/docker/docker v26.1.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 h1:IPrmumsT9t5BS7XcPhgsCTlkWbYg80SEXUzDpReaU6Y=
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11/go.mod h1:a6bNUGTbQBsY6VRHTr4h/rkOXjl244DyRD0tx3fgq4Q=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
33 changes: 2 additions & 31 deletions pkg/knuu/knuu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"fmt"
"os"
"os/signal"
"path"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand All @@ -21,6 +18,7 @@ import (
"github.com/celestiaorg/knuu/pkg/builder/kaniko"
"github.com/celestiaorg/knuu/pkg/instance"
"github.com/celestiaorg/knuu/pkg/k8s"
"github.com/celestiaorg/knuu/pkg/log"
"github.com/celestiaorg/knuu/pkg/minio"
"github.com/celestiaorg/knuu/pkg/system"
"github.com/celestiaorg/knuu/pkg/traefik"
Expand Down Expand Up @@ -103,7 +101,7 @@ func New(ctx context.Context, opts ...Option) (*Knuu, error) {

// handle default values
if k.Logger == nil {
k.Logger = defaultLogger()
k.Logger = log.DefaultLogger()
}

if k.TestScope == "" {
Expand Down Expand Up @@ -238,30 +236,3 @@ func (k *Knuu) handleTimeout(ctx context.Context) error {

return nil
}

func defaultLogger() *logrus.Logger {
logger := logrus.New()

logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := path.Base(f.File)
directory := path.Base(path.Dir(f.File))
return "", directory + "/" + filename + ":" + strconv.Itoa(f.Line)
},
})

// Enable reporting the file and line
logger.SetReportCaller(true)

customLevel := os.Getenv("LOG_LEVEL")
if customLevel != "" {
err := logger.Level.UnmarshalText([]byte(customLevel))
if err != nil {
logger.Warnf("Failed to parse LOG_LEVEL: %v, defaulting to INFO", err)
}
}
logger.Info("LOG_LEVEL: ", logger.GetLevel())

return logger
}
37 changes: 37 additions & 0 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package log

import (
"os"
"path"
"runtime"
"strconv"

"github.com/sirupsen/logrus"
)

func DefaultLogger() *logrus.Logger {
logger := logrus.New()

logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := path.Base(f.File)
directory := path.Base(path.Dir(f.File))
return "", directory + "/" + filename + ":" + strconv.Itoa(f.Line)
},
})

// Enable reporting the file and line
logger.SetReportCaller(true)

customLevel := os.Getenv("LOG_LEVEL")
if customLevel != "" {
err := logger.Level.UnmarshalText([]byte(customLevel))
if err != nil {
logger.Warnf("Failed to parse LOG_LEVEL: %v, defaulting to INFO", err)
}
}
logger.Info("LOG_LEVEL: ", logger.GetLevel())

return logger
}

0 comments on commit 7de0ce5

Please sign in to comment.