Coder Social home page Coder Social logo

call stack skipping about logr HOT 6 CLOSED

go-logr avatar go-logr commented on May 18, 2024
call stack skipping

from logr.

Comments (6)

pohly avatar pohly commented on May 18, 2024

Some potential solutions:

  • add additional functions like InfoDepth (as in klog)
  • WithCallerSkip/WithDepth/AddCallerSkip (as in zapr)

from logr.

pohly avatar pohly commented on May 18, 2024

I personally like WithCallerSkip best because it is more descriptive than WithDepth, consistent with WithValues (in contrast to AddCallerSkip), and avoids having to add two new functions for Info and Error.

Performance might be a concern. However, the struct that for example klogr needs to copy isn't big: https://github.com/uber-go/zap/blob/master/options.go#L108 (link from the extended klogr with two different output formats in PR kubernetes/klog#197).

I don't feel too strongly about it, though. I'm also fine with InfoDepth and ErrorDepth.

from logr.

thockin avatar thockin commented on May 18, 2024

I acknowledge why this is useful. Not every implementation logs line numbers, but it's common enough that this matters, IMO. Whatever we do here, implementations that don't log line numbers can just ignore this.

Adding methods is somewhat ugly. I instinctively lean away from a number-of-methods multiplier like this. We star with Info/Error. Then we add InfoDepth/ErrorDepth. Then at some future point we justify something else optional, and we end up with Info, Error, InfoDepth, ErrorDepth, InfoFoo, ErrorFoo, InfoDepthFoo, ErrorDepthFoo.

Adding args to methods is a breaking change, so pretty much off the table.

Adding some sort of options pattern seems best.

I spent some time thinking about it and I don't see a cleaner answer than something like:

func DebugLog(msg string, args ...string) {
    logger.WithCallDepth(1).V(debugV).Info(fmt.Sprintf("DBG: %s", msg), args...)
}

The name is open for debate, of course. Thoughts?

from logr.

thockin avatar thockin commented on May 18, 2024

PRs proposed

from logr.

pohly avatar pohly commented on May 18, 2024

Adding methods is somewhat ugly. I instinctively lean away from a number-of-methods multiplier like this.

That was also my thinking.

logger.WithCallDepth(1).V(debugV)

I'm fine with that.

from logr.

pohly avatar pohly commented on May 18, 2024

klogr implementation of WithCallDepth in https://github.com/pohly/klog/commits/klogr-call-depth

from logr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.