From 56160421d5eea6b9c196d98eaa88d278c5f18493 Mon Sep 17 00:00:00 2001 From: Ryota Sakamoto Date: Wed, 17 Apr 2024 23:48:09 +0900 Subject: [PATCH] Remove callSkip to prevent Logger.check error --- main.go | 2 +- pkg/logger/logger.go | 9 +++------ pkg/metrics/metrics.go | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 83131bc..bfb5017 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,6 @@ func loadControllerConfig() (config.ControllerConfig, error) { // getLoggerWithLogLevel returns logger with specific log level. func getLoggerWithLogLevel(logLevel string, logFilePath string) (logr.Logger, error) { - ctrlLogger := logger.New(logLevel, logFilePath, 2) + ctrlLogger := logger.New(logLevel, logFilePath) return zapr.NewLogger(ctrlLogger), nil } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 40e1c72..965f042 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -55,7 +55,7 @@ func getEncoder() zapcore.Encoder { return zapcore.NewJSONEncoder(encoderConfig) } -func (logConfig *Configuration) newZapLogger(callSkip int) *zap.Logger { //Logger { +func (logConfig *Configuration) newZapLogger() *zap.Logger { //Logger { var cores []zapcore.Core logLevel := getZapLevel(logConfig.LogLevel) @@ -66,11 +66,8 @@ func (logConfig *Configuration) newZapLogger(callSkip int) *zap.Logger { //Logge combinedCore := zapcore.NewTee(cores...) - // Allow callers to set value for call skip. The value should be 2 by default, but goroutines - // set it to 0 or 1 to avoid log stack errors. logger := zap.New(combinedCore, zap.AddCaller(), - zap.AddCallerSkip(callSkip), ) defer logger.Sync() @@ -105,12 +102,12 @@ func getLogWriter(logFilePath string) zapcore.WriteSyncer { } // New logger initializes logger -func New(logLevel, logLocation string, callSkip int) *zap.Logger { +func New(logLevel, logLocation string) *zap.Logger { inputLogConfig := &Configuration{ LogLevel: logLevel, LogLocation: logLocation, } - logger := inputLogConfig.newZapLogger(callSkip) + logger := inputLogConfig.newZapLogger() return logger } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 339ee2c..c3b2fbf 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -47,6 +47,6 @@ func setupMetricsServer() *http.Server { } func getMetricsLogger() logr.Logger { - ctrlLogger := logger.New("info", "", 0) + ctrlLogger := logger.New("info", "") return zapr.NewLogger(ctrlLogger) }