client/vendor/github.com/go-logr/logr
knative-automation 72aeb1c820
upgrade to latest dependencies (#1207)
bumping knative.dev/hack 8d623a0...8368e1f:
  > 8368e1f guard against set -o unset (# 49)
  > 2b4f6fc disable go's proxy and sumdb only for knative deps (# 47)
bumping knative.dev/networking 8b522a9...e24bdfe:
  > e24bdfe upgrade to latest dependencies (# 350)
  > ab1235e Bump a few assorted dependencies to their latest versions (# 349)
  > 45b7ed1 Add ingress conformance test to ensure we do not add retries (# 348)
  > b61da13 upgrade to latest dependencies (# 347)
  > d2088ff Update common github actions (# 346)
  > c069ad2 Create prober request with context right away (# 344)
  > 342a3fb upgrade to latest dependencies (# 342)
  > 94433ab upgrade to latest dependencies (# 341)
bumping knative.dev/pkg 6040b3a...a02dcff:
  > a02dcff Bump a few assorted dependencies to their latest versions (# 2013)
  > 4b2ae07 Replace deprecated github.com/markbates/inflect with github.com/gobuffalo/flect (# 2014)
  > 8878069 upgrade to latest dependencies (# 2010)
  > c493a9e Update common github actions (# 2009)
  > 6045ed4 Allow setting DisableCompression in NewAutoTransport (# 2007)
  > ca02ef7 Genreconciler properly generates reconciler for Resources with Status (# 2004)
  > 0d31134 Fix nil pointer panic in kvstore (# 2002)
bumping knative.dev/serving e61294b...8751d91:
  > 8751d91 Split the reconcile rollout into its own function (# 10722)
  > 2b95084 Optimize the execution path around logging (# 10720)
  > bbca20f Update net-contour nightly (# 10715)
  > ef39273 upgrade to latest dependencies (# 10719)
  > 6449fb8 upgrade to latest dependencies (# 10717)
  > 45a435a Update net-kourier nightly (# 10706)
  > 2fbef5f upgrade to latest dependencies (# 10713)
  > c4ea4ad Fix the analyzer config for load-testing benchmark since it must have a value (# 10709)
  > 6f46354 Apply k8s default values for readiness probe (# 10700)
  > 8c4b2ff Update net-certmanager nightly (# 10705)
  > b6f618b Update net-istio nightly (# 10704)
  > 390f2c2 bump k8s min in DEVELOPMENT.md (# 10699)
  > f2ccdd5 tests (# 10702)
  > 2090edf Update net-istio nightly (# 10695)
  > 789455d Update net-certmanager nightly (# 10674)
  > 1c61d3b Update common github actions (# 10697)
  > 2bc3650 Update net-kourier nightly (# 10696)
  > 8c64d92 Format markdown (# 10698)
  > 0e77ab2 Update net-kourier nightly (# 10676)
  > dd96a0a Update net-contour nightly (# 10686)
  > 8fbcfb0 Unpin the istio version and temporarily disable the error rate check analyzer (# 10655)
  > 58550fd Avoid adding gzip-encoding to requests implicitly (# 10691)
  > 60cdc35 Move Multi Container test to Beta (# 10683)
  > ae7b278 Update net-istio nightly (# 10687)
  > 7a18f38 Fix some nits in e2e tests (# 10678)
  > 9c572cd Allow to specify build platform for test images (# 10672)
  > 0ee79dd Remove the unsed struct items (# 10684)
  > 29da3af Improve debuggability of SKS logs (# 10679)
  > 8e1d587 upgrade to latest dependencies (# 10682)
  > aef0145 Temporarily disable auto TLS test with HTTP01 challenge  (# 10685)
  > 32b0292 Use lister instead of client to directly get ClusterDomainClaim (# 10677)
  > a19ff15 Update net-istio nightly (# 10675)
  > 6313088 Allow kpa to work with timeout in context (# 10673)
  > af7af61 Perform some test helper cleanup (# 10670)
  > 93d2449 upgrade to latest dependencies (# 10671)
  > 888331e Remove the service name from the internal traffic target object. (# 10669)
  > 1901e4c Use consistent alias for autoscaler v1alpha1 everywhere (# 10666)
  > 1e070a3 Remove context from MakeDecider (# 10657)
  > 452bed5 Further remove usage of the context in the scale runner (# 10653)
  > a1ee2ec bump ggcr & k8schain (# 10651)
  > 81818f9 Fix logging of errors in stats scraper (# 10654)
  > 1b0f43c Hide implementation detail inside a function (# 10652)
  > 756fd17 Update net-istio nightly (# 10648)
  > 6d46d52 Add support for decoding Revision from Host. (# 10647)
  > 01fa1a0 Remove the time computation (# 10645)
  > dbccf2a Do not pass context to the scale, but logger instead (# 10646)
  > ab176fa Rename back to the non deprecated name (# 10640)
  > fae6549 Update net-contour nightly (# 10644)
  > 5cd4f64 Update net-istio nightly (# 10643)
  > fbbbb98 Make route stop using the `DeprecatedServiceName` field (# 10638)
  > bf35e3f 💄 updating the HPAs to v2beta2 API usage (# 10631)
  > 51a9c0b Update net-certmanager nightly (# 10636)
  > e5c5c08 Export MESH env value in test script (# 10635)
  > 4a3274c Remove unused constants, make some other small tidy-ups (# 10637)
  > b083383 fix the broken doc's link (# 10634)
  > aac0df2 Deprecate the service name on the revision. (# 10633)
  > 0aa3d0b Remove the propagation from SKS->PA->Rev.Status of the K8s service (# 10632)
  > db90f4f Update net-contour nightly (# 10597)
  > 981c601 Update net-istio nightly (# 10619)
  > 8922f35 Update net-kourier nightly (# 10599)
  > df11c15 chore: Set background to white for autoscaling diagrams ... (# 10629)
  > f637b5a Remove naked returns (# 10618)
  > 6cde241 Improve rollout test to check duration (# 10625)
  > 7700811 At 100ms we still see failures on prow (# 10626)
  > c081a82 Make the singlethreaded code simpler by using boolean guard (# 10624)
  > 55a7edf upgrade to latest dependencies (# 10627)
  > 53d4d5b Fix some annoying nits in the route e2e tests (# 10623)
  > 2c781c7 upgrade to latest dependencies (# 10620)
  > 6dba44a The year was 2021.. (# 10621)
  > 39d33bf upgrade to latest dependencies (# 10617)
bumping golang.org/x/term 7de9c90...2321bbc:
  > 2321bbc Update doc to use "term" instead of "terminal"
  > ee85cb9 README.md: add badge to pkg.go.dev
bumping knative.dev/eventing ea452b5...3fcb645:
  > 3fcb645 🌀 Remvoing contrib refs (# 4855)
  > f05561d upgrade to latest dependencies (# 4853)
  > 37eaf71 switch Harwayne with antoineco (# 4850)
  > b887ac4 upgrade to latest dependencies (# 4848)
  > daa085d Format markdown (# 4846)
  > 3d51c72 Change trigger spec to indicate assigned broker should be immutable (# 4828)
  > 1774243 Add immutable fields validation to v1beta1 broker (# 4816)
  > 935d5fb Format markdown (# 4840)
  > 269b061 Update common github actions (# 4839)
  > 152e608 upgrade to latest dependencies (# 4841)
  > 8171448 Adding Logline for when a cloudevent has been successfully sent from APIServerSource to the sink (# 4723)
  > fd2688d Use SHOULD for TriggerSpec to keep compatibility (# 4838)
  > 1fa597e [# 4796] Bump golang lint timeout to 10m (# 4830)
  > a4a9f48 Format markdown (# 4829)
  > d58bd38 fix the link to head (# 4826)
  > 39d7a9e remove unused functions (# 4824)
  > 6edcbdd Panic in shared main to propagate error to exit code (# 4820)
  > 012a9bd v1beta1.Trigger delivery should be v1.DeliverySpec (# 4822)
  > 321a839 Format markdown (# 4823)
  > ec63881 Fix spec # 4515 (# 4654)
  > 1528750 upgrade to latest dependencies (# 4818)
  > 9dc57e2 Update common github actions (# 4817)
  > b20c96b sinkbing implement bindable (# 4794)
  > 8d51418 Bump golang linter version and timeout (# 4808)
  > f882ff0 Add availability rate to upgrade test report (# 4555)
  > a6635bb Patch HPA eventing-webhook min replicas (# 4811)
  > d46c1d0 It is already 2021 (# 4809)
  > fb8fbf7 Adding new source conformance testcase for CRD RBAC (# 4787)
  > 1725902 Update COMMUNITY_CONTACTS.md test grid link (# 4798)
  > b75d03a Adding new source conformance testcase for CRD Source Registry Spec (# 4780)
  > 77fc350 upgrade to latest dependencies (# 4797)

Signed-off-by: Knative Automation <automation@knative.team>
2021-02-09 10:04:50 -08:00
..
LICENSE Pin knative/pkg to release-0.17 (#976) 2020-08-11 12:23:05 -07:00
README.md upgrade to latest dependencies (#1207) 2021-02-09 10:04:50 -08:00
discard.go upgrade to latest dependencies (#1207) 2021-02-09 10:04:50 -08:00
go.mod update to k8s 0.19.7, go v1.15, fix gnostic (#1206) 2021-01-28 04:35:31 -08:00
logr.go upgrade to latest dependencies (#1207) 2021-02-09 10:04:50 -08:00

README.md

A more minimal logging API for Go

Before you consider this package, please read this blog post by the inimitable Dave Cheney. I really appreciate what he has to say, and it largely aligns with my own experiences. Too many choices of levels means inconsistent logs.

This package offers a purely abstract interface, based on these ideas but with a few twists. Code can depend on just this interface and have the actual logging implementation be injected from callers. Ideally only main() knows what logging implementation is being used.

Differences from Dave's ideas

The main differences are:

  1. Dave basically proposes doing away with the notion of a logging API in favor of fmt.Printf(). I disagree, especially when you consider things like output locations, timestamps, file and line decorations, and structured logging. I restrict the API to just 2 types of logs: info and error.

Info logs are things you want to tell the user which are not errors. Error logs are, well, errors. If your code receives an error from a subordinate function call and is logging that error and not returning it, use error logs.

  1. Verbosity-levels on info logs. This gives developers a chance to indicate arbitrary grades of importance for info logs, without assigning names with semantic meaning such as "warning", "trace", and "debug". Superficially this may feel very similar, but the primary difference is the lack of semantics. Because verbosity is a numerical value, it's safe to assume that an app running with higher verbosity means more (and less important) logs will be generated.

This is a BETA grade API.

There are implementations for the following logging libraries:

  • github.com/google/glog: glogr
  • k8s.io/klog: klogr
  • go.uber.org/zap: zapr
  • log (the Go standard library logger): stdr
  • github.com/sirupsen/logrus: logrusr
  • github.com/wojas/genericr: genericr (makes it easy to implement your own backend)
  • logfmt (Heroku style logging): logfmtr

FAQ

Conceptual

Why structured logging?

  • Structured logs are more easily queriable: Since you've got key-value pairs, it's much easier to query your structured logs for particular values by filtering on the contents of a particular key -- think searching request logs for error codes, Kubernetes reconcilers for the name and namespace of the reconciled object, etc

  • Structured logging makes it easier to have cross-referencable logs: Similarly to searchability, if you maintain conventions around your keys, it becomes easy to gather all log lines related to a particular concept.

  • Structured logs allow better dimensions of filtering: if you have structure to your logs, you've got more precise control over how much information is logged -- you might choose in a particular configuration to log certain keys but not others, only log lines where a certain key matches a certain value, etc, instead of just having v-levels and names to key off of.

  • Structured logs better represent structured data: sometimes, the data that you want to log is inherently structured (think tuple-link objects). Structured logs allow you to preserve that structure when outputting.

Why V-levels?

V-levels give operators an easy way to control the chattiness of log operations. V-levels provide a way for a given package to distinguish the relative importance or verbosity of a given log message. Then, if a particular logger or package is logging too many messages, the user of the package can simply change the v-levels for that library.

Why not more named levels, like Warning?

Read Dave Cheney's post. Then read Differences from Dave's ideas.

Why not allow format strings, too?

Format strings negate many of the benefits of structured logs:

  • They're not easily searchable without resorting to fuzzy searching, regular expressions, etc

  • They don't store structured data well, since contents are flattened into a string

  • They're not cross-referencable

  • They don't compress easily, since the message is not constant

(unless you turn positional parameters into key-value pairs with numerical keys, at which point you've gotten key-value logging with meaningless keys)

Practical

Why key-value pairs, and not a map?

Key-value pairs are much easier to optimize, especially around allocations. Zap (a structured logger that inspired logr's interface) has performance measurements that show this quite nicely.

While the interface ends up being a little less obvious, you get potentially better performance, plus avoid making users type map[string]string{} every time they want to log.

What if my V-levels differ between libraries?

That's fine. Control your V-levels on a per-logger basis, and use the WithName function to pass different loggers to different libraries.

Generally, you should take care to ensure that you have relatively consistent V-levels within a given logger, however, as this makes deciding on what verbosity of logs to request easier.

But I really want to use a format string!

That's not actually a question. Assuming your question is "how do I convert my mental model of logging with format strings to logging with constant messages":

  1. figure out what the error actually is, as you'd write in a TL;DR style, and use that as a message

  2. For every place you'd write a format specifier, look to the word before it, and add that as a key value pair

For instance, consider the following examples (all taken from spots in the Kubernetes codebase):

  • klog.V(4).Infof("Client is returning errors: code %v, error %v", responseCode, err) becomes logger.Error(err, "client returned an error", "code", responseCode)

  • klog.V(4).Infof("Got a Retry-After %ds response for attempt %d to %v", seconds, retries, url) becomes logger.V(4).Info("got a retry-after response when requesting url", "attempt", retries, "after seconds", seconds, "url", url)

If you really must use a format string, place it as a key value, and call fmt.Sprintf yourself -- for instance, log.Printf("unable to reflect over type %T") becomes logger.Info("unable to reflect over type", "type", fmt.Sprintf("%T")). In general though, the cases where this is necessary should be few and far between.

How do I choose my V-levels?

This is basically the only hard constraint: increase V-levels to denote more verbose or more debug-y logs.

Otherwise, you can start out with 0 as "you always want to see this", 1 as "common logging that you might possibly want to turn off", and 10 as "I would like to performance-test your log collection stack".

Then gradually choose levels in between as you need them, working your way down from 10 (for debug and trace style logs) and up from 1 (for chattier info-type logs).

How do I choose my keys

  • make your keys human-readable
  • constant keys are generally a good idea
  • be consistent across your codebase
  • keys should naturally match parts of the message string

While key names are mostly unrestricted (and spaces are acceptable), it's generally a good idea to stick to printable ascii characters, or at least match the general character set of your log lines.