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

fix: caller location error in logs #2367

Merged
merged 2 commits into from
Mar 16, 2022
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
4 changes: 3 additions & 1 deletion api/internal/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ func InitLogger() {
func GetLogger(logType Type) *zap.SugaredLogger {
_ = zap.RegisterSink("winfile", newWinFileSink)

skip := 2
writeSyncer := fileWriter(logType)
encoder := getEncoder(logType)
logLevel := getLogLevel()
if logType == AccessLog {
logLevel = zapcore.InfoLevel
skip = 0
}

core := zapcore.NewCore(encoder, writeSyncer, logLevel)

zapLogger := zap.New(core, zap.AddCaller(), zap.AddCallerSkip(2))
zapLogger := zap.New(core, zap.AddCaller(), zap.AddCallerSkip(skip))

return zapLogger.Sugar()
}
Expand Down
3 changes: 3 additions & 0 deletions api/test/shell/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ stop_dashboard() {
stop_dashboard 6

[ $(grep -c "/apisix/admin/user/login" "${ACCESS_LOG_FILE}") -ne '0' ]

# check logging middleware
[ $(grep -c "filter/logging.go" "${ACCESS_LOG_FILE}") -ne '0' ]
}

#8
Expand Down