Comments (6)
Some potential solutions:
- add additional functions like
InfoDepth
(as in klog) WithCallerSkip
/WithDepth
/AddCallerSkip
(as in zapr)
from logr.
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.
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.
PRs proposed
from logr.
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.
klogr implementation of WithCallDepth in https://github.com/pohly/klog/commits/klogr-call-depth
from logr.
Related Issues (20)
- my maps project
- WithValues with the same key repeats the field HOT 4
- Create `slogr` implementation for `slog` package HOT 6
- Create `charmbracelet/log` implementation HOT 3
- why `V` function make level additive? HOT 2
- How could I transfer the caller information into Json format? HOT 5
- Add minimal permissions to GitHub workflows
- Add a security policy
- PR #166 introduced a breaking change in a patch release HOT 7
- Why use WithName() HOT 7
- Add OpenSSF Scorecard workflow HOT 2
- Hash-pin workflow dependencies
- add support for slog.LogValuer
- Consider changing how keys are namespaced
- Consider a "group" construct to match slog
- Consider allowing timestamp to be passed into LogSink
- Consider allowing PC to be passed into Handler HOT 3
- Bump min Go version to at least 18? HOT 1
- TODO: Write a nice doc on logr <-> slog
- Enabled + stack unwinding HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logr.