Comments (3)
At best, these would be optional interfaces, so you'd have to do something like:
func myFunc(log logr.Logger) {
if name, ok := log.GetName(); ok {
if name != "something" {
log = log.WithName("something")
}
}
}
Underneath, it would test the LogSink for support and tell you if it supported it or not.
Deleting a key would be the same, though I am more suspicious of that use-case.
A more DIY approach would be something like:
func MyFunc(log logr.Logger) {
myFuncInternal(logr.WithName("something").WithValues("key", "value"))
}
func myFuncInternal(log logr.Logger) {
// do stuff
// recursion calls myFuncInternal
}
from logr.
I have duplicates of the key key with different values which makes the field useless.
I'm not so sure about this. My understanding of the "repeated key" semantic is that the last valye wins, so (in JSON) {"foo": "bar", "foo": "x"}
would be equivalent to {"foo": "x"}
. But later I learned that the JSON spec doesn't actually guarantee that. It's up to the parser which value it uses.
This makes it a problem of the log backend. The klog text backend doesn't de-duplicate logger.WithValues("foo", "var").WithValues("foo", "x")
. It does de-duplicate logger.WithValues("foo", "bar").Info("something", "foo", "x")
. My rationale was that WithValues
is easier to keep under control such that keys are unique, whereas duplication of keys with log calls is currently unavoidable in Kubernetes (contextual logging and thus WithValues is optional). Given what you described it would make more sense to always de-duplicate everything, even if that causes overhead.
zap doesn't de-duplicate. It seems to rely on JSON parsers using the latest value.
from logr.
Strictly, JSON fields are reorderable. Practically, I think plenty of things depen on in-order processing.
FWIW: funcr does not de-dup keys, either. It could de-dup across successive WithValues
calls, but de-duping across WithValues
and Info
/Error
calls is harder and more expensive (WithValues
is pre-rendered).
from logr.
Related Issues (20)
- 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
- contextual logging for slog HOT 31
- funcr Feature Request: Add LogInfoLevel Option to skip logging level in the info log HOT 6
- TODO circa Go 1.24: Remove non-slog code and consolidate files
- Cut a new release (v1.4.0?) HOT 7
- Typesafe API HOT 4
- Unable to print Warn Logs when using logr/zapr HOT 5
- Metrics for logged messages HOT 5
- funcr: slog output omits intermediate groups HOT 7
- I am facing log/slog is no in std (/usr/local/go/src/log/slog) HOT 5
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.