From fa877ca6f1301e2205f1cec6ad2f1abf1ec34e6b Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Thu, 6 Apr 2023 14:24:25 -0600 Subject: [PATCH] Add klog logrus bridge --- cmd/kubectl-argo-rollouts/main.go | 5 +++++ go.mod | 3 ++- go.sum | 4 ++++ utils/log/log.go | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/kubectl-argo-rollouts/main.go b/cmd/kubectl-argo-rollouts/main.go index e5bc3121f6..2d4badbad1 100644 --- a/cmd/kubectl-argo-rollouts/main.go +++ b/cmd/kubectl-argo-rollouts/main.go @@ -1,6 +1,8 @@ package main import ( + "github.com/bombsimon/logrusr/v2" + "github.com/sirupsen/logrus" "os" "k8s.io/cli-runtime/pkg/genericclioptions" @@ -15,6 +17,9 @@ import ( func main() { klog.InitFlags(nil) + logrusLog := logrus.New() + logger := logrusr.New(logrusLog) + klog.SetLogger(logger) streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} o := options.NewArgoRolloutsOptions(streams) root := cmd.NewCmdArgoRollouts(o) diff --git a/go.mod b/go.mod index 2b6fe5d719..35a611c13f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/argoproj/argo-rollouts -go 1.19 +go 1.29 require ( github.com/antonmedv/expr v1.12.5 @@ -11,6 +11,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.25.7 github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.19.7 github.com/blang/semver v3.5.1+incompatible + github.com/bombsimon/logrusr/v2 v2.0.1 github.com/evanphx/json-patch/v5 v5.6.0 github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index 4b3e71a4fd..639bfdc97a 100644 --- a/go.sum +++ b/go.sum @@ -174,6 +174,8 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM= +github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2lc5YJvzmOJio= github.com/bradleyfalzon/ghinstallation/v2 v2.1.0 h1:5+NghM1Zred9Z078QEZtm28G/kfDfZN/92gkDlLwGVA= github.com/bradleyfalzon/ghinstallation/v2 v2.1.0/go.mod h1:Xg3xPRN5Mcq6GDqeUVhFbjEWMb4JHCyWEeeBGEYQoTU= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= @@ -332,6 +334,7 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= +github.com/go-logr/logr v1.0.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -1228,6 +1231,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/utils/log/log.go b/utils/log/log.go index f2b36b078c..73fd0405b5 100644 --- a/utils/log/log.go +++ b/utils/log/log.go @@ -2,6 +2,8 @@ package log import ( "flag" + "github.com/bombsimon/logrusr/v2" + "github.com/sirupsen/logrus" "strconv" "strings" @@ -31,6 +33,9 @@ const ( // SetKLogLevel set the klog level for the k8s go-client func SetKLogLevel(klogLevel int) { klog.InitFlags(nil) + logrusLog := logrus.New() + logger := logrusr.New(logrusLog) + klog.SetLogger(logger) _ = flag.Set("logtostderr", "true") _ = flag.Set("v", strconv.Itoa(klogLevel)) }