Skip to content

[Bug] The caller depth of log.Filter should be the same as log.logger. #2954

@kvii

Description

@kvii

What happened:

Caller depth changed after create a log.Filter.

What you expected to happen:

log.Filter should print the same caller depth as log.logger.

How to reproduce it (as minimally and precisely as possible):

package main

import (
	"github.com/go-kratos/kratos/v2/log"
)

func main() {
	// common use case: caller is displayed correctly.
	l1 := log.With(log.DefaultLogger,
		"caller", log.DefaultCaller,
	)
	h1 := log.NewHelper(l1)
	h1.Info("h1") // INFO caller=playground/main.go:12 msg=h1

	// after add a Filter: caller depth +1
	l2 := log.NewFilter(l1)
	h2 := log.NewHelper(l2)
	h2.Info("h2") // INFO caller=log/helper.go:91 msg=h2

	// Note: Can't write some code like log.Caller(depth + 1).
	// Because log.NewFilter and log.With can be nested, like
	// log.With(log.NewFilter(log.With(l)))
}

Anything else we need to know?:

Can't write some code like log.Caller(depth + 1). Because log.NewFilter and log.With can be nested, like log.With(log.NewFilter(log.With(l))).

Environment:

  • Kratos version (use kratos -v): kratos version v2.7.0
  • Go version (use go version): go version go1.21.0 darwin/arm64
  • OS (e.g: cat /etc/os-release): mac os Ventura 13.5 (22G74) with m1 pro

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions