-
Notifications
You must be signed in to change notification settings - Fork 5
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
support key/value checking for arbitrary functions #22
Comments
Perhaps something similar can be done here? Alternatively, support special comment tags? |
Hi, did you mean loggercheck? I decided to focus on Speaking about checking |
No, https://github.com/kubernetes-sigs/logtools/tree/main/logcheck. Some of its functionality is specific to the migration to structured, contextual logging in Kubernetes, therefore I have not tried to make it more general or get it included in golangci-lint.
The intention wasn't to add any special support for other loggers. But when wrappers can be marked or detected, then other logging libraries can enable sloglint. For example, there's https://github.com/kubernetes/klog/blob/2086216a5034ba7c4e3a4fec7d89c5d0434eb1a0/klog.go#L1461-L1467 That could become:
Then sloglint will warn about |
It's here: https://cs.opensource.google/go/x/tools/+/refs/tags/v0.14.0:go/analysis/passes/printf/printf.go
It would work for Kubernetes, but the list would be long and everyone else using klog would have to copy it into their own golangci-lint config. Automatic detection would be nicer 😁 |
Another example where I would like to use it:
|
So, I'll work on the wrappers support and let you know 🤝 |
klog can be used as wrapper around slog - it's a bit more flexible than that, though. But the net effect is the same: the same rules as for slog key/value pairs also apply to it. So yes, your understanding is correct. |
I'd like to express interest in this use-case, as well. We have our own log package that wraps slog, but would like to apply this linter against our code. We can do so today by cloning this code and modifying I will note that loggercheck has a way to add custom rules as a list of additional function/method signatures eg.
But loggercheck doesn't work with Attrs, just key-value pairs, which is why we like sloglint. :) |
@tstraley Could you provide an example of the wrappers you use? I'm currently researching the possibility to automate detection of slog wrappers, without the need to specify custom rules first. It'd help a lot, thanks. |
@tmzane The wrapper my team uses looks like this:
This is mostly to provide helper functions for custom levels.
Where We also have overrides of Specifically this, where we use to do
|
@tmzane: gentle ping regarding this... it would be great to get this working because in Kubernetes we start to have more APIs which accept log parameters and currently have no linter for those. Our own "logtools/logcheck" doesn't support it either yet. |
Hey, sorry for the late reply, I'm kinda busy these days. I've actually got something close to working regarding this feature, just need a bit more work to handle edge cases. I'm going to get back to it as soon as I have some free time. Will let you know when there is something ready for testing. |
The
slog.Logger
API is just one of possible many other high-level APIs which accept key/value pairs. Another example isgo-logr/logr.Logger
and some custom wrapper functions in Kubernetes.It would be great if sloglint could also warn about incorrect parameters in those other methods.
Disclaimer: I'm the maintainer of logcheck, a linter which does similar checking for go-logr APIs, and of logging in Kubernetes. Long-term sloglint could replace or supplant logcheck.
The text was updated successfully, but these errors were encountered: