diff --git a/README.md b/README.md index 8969526..7c7f0c6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # A minimal logging API for Go [![Go Reference](https://pkg.go.dev/badge/github.com/go-logr/logr.svg)](https://pkg.go.dev/github.com/go-logr/logr) +[![Go Report Card](https://goreportcard.com/badge/github.com/go-logr/logr)](https://goreportcard.com/report/github.com/go-logr/logr) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/go-logr/logr/badge)](https://securityscorecards.dev/viewer/?platform=github.com&org=go-logr&repo=logr) logr offers an(other) opinion on how Go programs and libraries can do logging diff --git a/examples/tab_logger.go b/examples/tab_logger.go index b7335f5..4e00598 100644 --- a/examples/tab_logger.go +++ b/examples/tab_logger.go @@ -36,10 +36,10 @@ var _ logr.LogSink = &tabLogSink{} // Note that Init usually takes a pointer so it can modify the receiver to save // runtime info. -func (_ *tabLogSink) Init(info logr.RuntimeInfo) { +func (*tabLogSink) Init(info logr.RuntimeInfo) { } -func (_ tabLogSink) Enabled(level int) bool { +func (tabLogSink) Enabled(level int) bool { return true } diff --git a/examples/usage_example.go b/examples/usage_example.go index 7f736fe..e60db7a 100644 --- a/examples/usage_example.go +++ b/examples/usage_example.go @@ -51,17 +51,20 @@ var objectMap = map[string]Object{ }, } +// Object is an app contruct that might want to be logged. type Object struct { Name string Kind string Details any } +// Client is a simulated client in this example app. type Client struct { objects map[string]Object log logr.Logger } +// Get retrieves an object. func (c *Client) Get(key string) (Object, error) { c.log.V(1).Info("fetching object", "key", key) obj, ok := c.objects[key] @@ -72,6 +75,7 @@ func (c *Client) Get(key string) (Object, error) { return obj, nil } +// Save stores an object. func (c *Client) Save(obj Object) error { c.log.V(1).Info("saving object", "key", obj.Name, "object", obj) if rand.Intn(2) == 0 { @@ -81,6 +85,7 @@ func (c *Client) Save(obj Object) error { return nil } +// WatchNext waits for object updates. func (c *Client) WatchNext() string { time.Sleep(2 * time.Second) @@ -98,12 +103,14 @@ func (c *Client) WatchNext() string { return "" } +// Controller is the main point of this example. type Controller struct { log logr.Logger expectedKind string client *Client } +// Run starts the example controller. func (c *Controller) Run() { c.log.Info("starting reconciliation") @@ -141,6 +148,7 @@ func (c *Controller) Run() { c.log.Info("stopping reconciliation") } +// NewController allocates and initializes a Controller. func NewController(log logr.Logger, objectKind string) *Controller { ctrlLogger := log.WithName("controller").WithName(objectKind) client := &Client{