Comments (11)
There should be output at levels 0
and 1
by default (since those actually correspond to Zap levels under the hood). the ZapLogger
method just creates a "sane" default configuration for using Zap as the log implementation, so it's possible to set up Zap however you want (see below for an example).
That being said, I'd highly encourage avoiding numeric verbosity levels if you can in favor of filtering on logger prefixes (and potentially actual tags -- I've got some ideas for making that easier) -- it's really easy for numeric verbosity levels to lose their meaning.
Example for setting up Zap in a different configuration:
(Note the message in the zapr documentation: log level 1 corresponds to debug, level 2 corresponds to -2, level 3 corresponds to -3, etc).
import (
"log"
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func MyZapLogger() (logr.Logger, zap.AtomicLevel) {
cfg := zap.NewDevelopmentConfig()
zapLog, err := zapLogCfg.Build(zap.AddCallerSkip(1))
if err != nil {
log.Fatalf(err) // who watches the watchmen?
}
// the AtomicLevel can be used to dynamically adjust the logging level
// there's a helper function (zap.LevelFlag) to add a flag for adjusting it too
return zapr.NewLogger(zapLog), cfg.Level
}
from controller-runtime.
That being said, it should be easier to get the "default" config and turn that into a logger in two steps to allow for easy tweaking.
from controller-runtime.
Thank you @DirectXMan12, I will follow your indications. I think you can close this issue.
FYI: When trying to use other log levels smaller than -1 (e.g. V(2)) with cfg := zap.NewProductionConfig()
(with development config works fine) I've got the following panic error. So I will use just the already defined zap log levels to avoid this.
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/zapcore.(*counters).get(0xc0001d2000, 0xc000151cfe, 0xbb762a, 0xc, 0xc000151be0)
/home/x/go/src/github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/zapcore/sampler.go:48 +0x79
github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/zapcore.(*sampler).Check(0xc00018f560, 0xfe, 0xbee5907d06b7cfd4, 0x2a36d55, 0x11b62a0, 0xbb4baf, 0x7, 0xbb762a, 0xc, 0x0, ...)
/home/x/go/src/github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/zapcore/sampler.go:128 +0x9d
github.com/presslabs/mysql-operator/vendor/go.uber.org/zap.(*Logger).check(0xc0000a91a0, 0x40bffe, 0xbb762a, 0xc, 0xc00010e501)
/home/x/go/src/github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/logger.go:269 +0x137
github.com/presslabs/mysql-operator/vendor/go.uber.org/zap.(*Logger).Check(0xc0000a91a0, 0xb2a0fe, 0xbb762a, 0xc, 0xfffffffffffffffe)
/home/x/go/src/github.com/presslabs/mysql-operator/vendor/go.uber.org/zap/logger.go:172 +0x48
github.com/presslabs/mysql-operator/vendor/github.com/go-logr/zapr.(*infoLogger).Info(0xc0000bba40, 0xbb762a, 0xc, 0x0, 0x0, 0x0)
/home/x/go/src/github.com/presslabs/mysql-operator/vendor/github.com/go-logr/zapr/zapr.go:69 +0x4e
main.main()
/home/x/go/src/github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar/main.go:119 +0x62f
from controller-runtime.
huh, can you file a bug against https://github.com/go-logr/zapr so that I can take a peek and/or add some docs? Thanks!
from controller-runtime.
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
from controller-runtime.
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
from controller-runtime.
/remove-lifecycle rotten
from controller-runtime.
/good-first-issue
/kind feature
/priority backlog
from controller-runtime.
@DirectXMan12:
This request has been marked as suitable for new contributors.
Please ensure the request meets the requirements listed here.
If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue
command.
In response to this:
/good-first-issue
/kind feature
/priority backlog
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
from controller-runtime.
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
from controller-runtime.
closing, we've now got options to configure the underlying zap logger.
from controller-runtime.
Related Issues (20)
- Consistently Seeing Reflector Watch Errors on Controller Shutdown HOT 6
- Add interface assertion for delegatingByGVKCache
- CreateOrUpdate ergonomics in presence of defaults HOT 2
- adding opts for WatchFunc in informers HOT 1
- 🐛 Webhook builder allows passing in more than one `For` type which gets overridden by the last type.
- Go Version Format is incorrect HOT 3
- github.com/prometheus/common v0.48.0 is incompatible with Kubernetes HOT 4
- Allow modifying context per `Reconcile(ctx context.Context, req ctrl.Request)` HOT 3
- Incompatibility Issue with controller-runtime Version Pinning and envtest Setup - It is requiring go 1.22 when the latest release still using go 1.21 as old project versions HOT 3
- Unstructured converter panics if the destination struct contains private fields HOT 3
- Multi Cluster Example / Pattern HOT 9
- Panic in `runnableGroup`'s `Add` and `StopAndWait` due to a data race HOT 1
- Cannot run / install specific versions of setup-envtest due to missing submodule tag HOT 2
- Data race during manager shutdown HOT 2
- Add a validation script to verify go.mod is in sync with k/k HOT 3
- Enhancement of Authentication and Authorization Filters to Allow Custom Configurations and Stability Improvements HOT 4
- Data race with various client APIs HOT 3
- Allow to ignore globalPredicates for specific resources HOT 1
- Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet HOT 8
- Use setup-envtest from (test) code HOT 18
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 controller-runtime.