README.md
1klog
2====
3
4klog is a permanent fork of https://github.com/golang/glog.
5
6## Why was klog created?
7
8The decision to create klog was one that wasn't made lightly, but it was necessary due to some
9drawbacks that are present in [glog](https://github.com/golang/glog). Ultimately, the fork was created due to glog not being under active development; this can be seen in the glog README:
10
11> The code in this repo [...] is not itself under development
12
13This makes us unable to solve many use cases without a fork. The factors that contributed to needing feature development are listed below:
14
15 * `glog` [presents a lot "gotchas"](https://github.com/kubernetes/kubernetes/issues/61006) and introduces challenges in containerized environments, all of which aren't well documented.
16 * `glog` doesn't provide an easy way to test logs, which detracts from the stability of software using it
17 * A long term goal is to implement a logging interface that allows us to add context, change output format, etc.
18
19Historical context is available here:
20
21 * https://github.com/kubernetes/kubernetes/issues/61006
22 * https://github.com/kubernetes/kubernetes/issues/70264
23 * https://groups.google.com/forum/#!msg/kubernetes-sig-architecture/wCWiWf3Juzs/hXRVBH90CgAJ
24 * https://groups.google.com/forum/#!msg/kubernetes-dev/7vnijOMhLS0/1oRiNtigBgAJ
25
26----
27
28How to use klog
29===============
30- Replace imports for `"github.com/golang/glog"` with `"k8s.io/klog/v2"`
31- Use `klog.InitFlags(nil)` explicitly for initializing global flags as we no longer use `init()` method to register the flags
32- You can now use `log_file` instead of `log_dir` for logging to a single file (See `examples/log_file/usage_log_file.go`)
33- If you want to redirect everything logged using klog somewhere else (say syslog!), you can use `klog.SetOutput()` method and supply a `io.Writer`. (See `examples/set_output/usage_set_output.go`)
34- For more logging conventions (See [Logging Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md))
35
36**NOTE**: please use the newer go versions that support semantic import versioning in modules, ideally go 1.11.4 or greater.
37
38### Coexisting with klog/v2
39
40See [this example](examples/coexist_klog_v1_and_v2/) to see how to coexist with both klog/v1 and klog/v2.
41
42### Coexisting with glog
43This package can be used side by side with glog. [This example](examples/coexist_glog/coexist_glog.go) shows how to initialize and synchronize flags from the global `flag.CommandLine` FlagSet. In addition, the example makes use of stderr as combined output by setting `alsologtostderr` (or `logtostderr`) to `true`.
44
45## Community, discussion, contribution, and support
46
47Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
48
49You can reach the maintainers of this project at:
50
51- [Slack](https://kubernetes.slack.com/messages/klog)
52- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-sig-architecture)
53
54### Code of conduct
55
56Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).
57
58----
59
60glog
61====
62
63Leveled execution logs for Go.
64
65This is an efficient pure Go implementation of leveled logs in the
66manner of the open source C++ package
67 https://github.com/google/glog
68
69By binding methods to booleans it is possible to use the log package
70without paying the expense of evaluating the arguments to the log.
71Through the -vmodule flag, the package also provides fine-grained
72control over logging at the file level.
73
74The comment from glog.go introduces the ideas:
75
76 Package glog implements logging analogous to the Google-internal
77 C++ INFO/ERROR/V setup. It provides functions Info, Warning,
78 Error, Fatal, plus formatting variants such as Infof. It
79 also provides V-style logging controlled by the -v and
80 -vmodule=file=2 flags.
81
82 Basic examples:
83
84 glog.Info("Prepare to repel boarders")
85
86 glog.Fatalf("Initialization failed: %s", err)
87
88 See the documentation for the V function for an explanation
89 of these examples:
90
91 if glog.V(2) {
92 glog.Info("Starting transaction...")
93 }
94
95 glog.V(2).Infoln("Processed", nItems, "elements")
96
97
98The repository contains an open source version of the log package
99used inside Google. The master copy of the source lives inside
100Google, not here. The code in this repo is for export only and is not itself
101under development. Feature requests will be ignored.
102
103Send bug reports to golang-nuts@googlegroups.com.
104