Move logrus setup code to log package

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2023-04-24 10:14:13 -07:00
parent fdd1be6734
commit 370be0c18f
4 changed files with 64 additions and 41 deletions

View File

@@ -30,7 +30,6 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"k8s.io/klog/v2"
criconfig "github.com/containerd/containerd/pkg/cri/config"
@@ -111,24 +110,21 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
// Set glog level.
func setGLogLevel() error {
l := logrus.GetLevel()
l := log.GetLevel()
fs := flag.NewFlagSet("klog", flag.PanicOnError)
klog.InitFlags(fs)
if err := fs.Set("logtostderr", "true"); err != nil {
return err
}
switch l {
case logrus.TraceLevel:
case log.TraceLevel:
return fs.Set("v", "5")
case logrus.DebugLevel:
case log.DebugLevel:
return fs.Set("v", "4")
case logrus.InfoLevel:
case log.InfoLevel:
return fs.Set("v", "2")
// glog doesn't support following filters. Defaults to v=0.
case logrus.WarnLevel:
case logrus.ErrorLevel:
case logrus.FatalLevel:
case logrus.PanicLevel:
default:
// glog doesn't support other filters. Defaults to v=0.
}
return nil
}