Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove callSkip to prevent Logger.check error #254

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading