Skip to content

Commit

Permalink
Remove callSkip to prevent Logger.check error (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-sakamoto committed Apr 20, 2024
1 parent 3b117c2 commit f072588
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 3 additions & 6 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit f072588

Please sign in to comment.