-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feature: logging deep callers #5
Conversation
Technically, this is a nice and simple change, everything clear and make sense. However, conceptually I have a few issues with this approach:
The bottom line - I think this approach won't be any practical by the same reason why CallerSkip wasn't any good - it requires some kind of "static logger routing", i.e. making and passing multiple loggers unless we (and user) willing to introduce tight coupling with type assertion to I have mentioned an alternative way - |
All the problems you mention can be solved if we modify type L interface {
Logf(format string, args ...interface{})
LogfForDepth(calldepth int, format string, args ...interface{})
} Clients that don't want to log deep callers can use short form of the interface (the current one), the clients that do want this logging will use an extended form.
I don't see this advice in README. Moreover, I see this advice: "pass the concrete logger as a dependency".
Consider this from the prospective of some module that needs to log indirect callers. If we combine this approach with "make your own interface with Logf and use it" advice then we must conclude that there must be a method for the module to express a list of unwanted callers which is currently absent. |
Extending the current simple and nice single-method interface with such an exotic method feels very wrong to me.
yeah, my bad. I didn't communicate this part clear enough in README. The proper use case I had in mind is to avoid any coupling with the particular logger by defining and accepting local interface and not passing lgr.L around. This is, for example, done in go-pkgz/auth. The advice you quoted meant to say "don't use a global logger if you can avoid it"
I don't get it. The one (re)defining and using lgr only need to have a single Logf method implemented/delegated. If our constructor allows such option it won't affect interface in any visible way. This is pretty much the same as all other options we support. And we already have such option CallerIgnore, it just half baked, not documented and respected in narrow cases only. |
I mean this: // ... inside some package that needs to log indirect callers
func foo() {
bar() // I want this call to be logged
}
func bar() {
lgr.DefaultForDepth(1).Logf("[INFO] xxx")
// some other work
} With my approach the author (!) of a package can say type L interface {
Logf(format string, args ...interface{})
}
var l L
func foo() {
bar() // I want this call to be logged ...
}
func bar() {
l.Logf("[INFO] xxx") // ... but not this. How can I express this?
// some other work
} |
You mention in #2 that there is a need for logging deep callers. Example.