我创建了一个记录器kubebuilder
,它基于 zap 记录器:
import (
"flag"
"github.com/gin-gonic/gin"
"net/http"
"os"
"go.uber.org/zap/zapcore"
uzap "go.uber.org/zap"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
var zapOpts []uzap.Option
zapOpts = append(zapOpts, uzap.AddCaller())
zapOpts = append(zapOpts, uzap.AddCallerSkip(1))
zapOpts = append(zapOpts, uzap.AddStacktrace(uzap.DebugLevel))
opts := zap.Options{
Development: developmentFlag,
StacktraceLevel: stacktraceLevel,
Level: level,
Encoder: encoder,
ZapOpts: zapOpts,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
现在我想将日志级别更改zapcore.InfoLevel
为运行时。我没有找到任何SetLogLevel
或类似的 API。
我是否需要创建新选项然后设置新级别?
我还需要用sigs.k8s.io/controller-runtime/pkg/log/zap
库设置记录器。记录器的接口来自go-logr
并实现logr.Logger
接口。如果我尝试将其更改为,zapcore.NewCore
我将无法再设置记录器ctrl.SetLogger
。
我想保留更新所有选项zap.Options
并更改日志级别的选项,并且仍然使用来自sigs.k8s.io/controller-runtime/pkg/log/zap
.
可以用
sigs.k8s.io/controller-runtime/pkg/log/zap
and来做sigs.k8s.io/controller-runtime
吗?