CINXE.COM
external/github.com/kubernetes/klog - Git at Google
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>external/github.com/kubernetes/klog - Git at Google</title><link rel="stylesheet" type="text/css" href="/+static/base.css"><link rel="stylesheet" type="text/css" href="/+static/doc.css"><!-- default customHeadTagPart --></head><body class="Site"><header class="Site-header"><div class="Header"><a class="Header-image" href="/"><img src="//www.gstatic.com/images/branding/lockups/2x/lockup_git_color_108x24dp.png" width="108" height="24" alt="Google Git"></a><div class="Header-menu"> <a class="Header-menuItem" href="https://accounts.google.com/AccountChooser?faa=1&service=gerritcodereview&continue=https://chromium.googlesource.com/login/external/github.com/kubernetes/klog/">Sign in</a> </div></div></header><div class="Site-content"><div class="Container "><div class="Breadcrumbs"><a class="Breadcrumbs-crumb" href="/?format=HTML">chromium</a> / <a class="Breadcrumbs-crumb" href="/external/">external</a> / <a class="Breadcrumbs-crumb" href="/external/github.com/">github.com</a> / <a class="Breadcrumbs-crumb" href="/external/github.com/kubernetes/">kubernetes</a> / <span class="Breadcrumbs-crumb">klog</span></div><div class="CloneRepo"><div class="CloneRepo-title">Clone this repo:</div><input id="clone-repo-input" type="text" class="u-monospace CloneRepo-command" readonly="readonly" value="git clone https://chromium.googlesource.com/external/github.com/kubernetes/klog"></div><div class="RepoShortlog"><div class="RepoShortlog-refs"><div class="RefList RefList--responsive"><h3 class="RefList-title">Branches</h3><ul class="RefList-items"><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/main">main</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/upstream/dims-patch-1">upstream/dims-patch-1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/upstream/fix_typo">upstream/fix_typo</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/upstream/flag_defaults">upstream/flag_defaults</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/upstream/main">upstream/main</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/heads/upstream/release-1.x">upstream/release-1.x</a></li></ul></div><div class="RefList RefList--responsive"><h3 class="RefList-title">Tags</h3><ul class="RefList-items"><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.130.1">upstream/v2.130.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.130.0">upstream/v2.130.0</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.120.1">upstream/v2.120.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.120.0">upstream/v2.120.0</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.110.1">upstream/v2.110.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.100.1">upstream/v2.100.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.90.1">upstream/v2.90.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.90.0">upstream/v2.90.0</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.80.1">upstream/v2.80.1</a></li><li class="RefList-item"><a href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.80.0">upstream/v2.80.0</a></li></ul></div><a href="/external/github.com/kubernetes/klog/+refs">More...</a></div><div class="RepoShortlog-log"><ol class="CommitLog"><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/external/github.com/kubernetes/klog/+/69472594defe33aee4442f9266aadfddc89fe4b0">6947259</a> <a href="/external/github.com/kubernetes/klog/+/69472594defe33aee4442f9266aadfddc89fe4b0">Merge pull request #245 from dims/update-go-versions-we-test</a> <span class="CommitLog-author" title="k8s-ci-robot@users.noreply.github.com">by Kubernetes Prow Robot</span> <span class="CommitLog-time" title="Thu Jun 03 01:41:38 2021">路 3 years, 6 months ago</span> <a class="CommitLog-branchLabel" href="/external/github.com/kubernetes/klog/+/refs/heads/main">main</a></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/external/github.com/kubernetes/klog/+/567ef13033a7916bdca02fd1b572b97fcc8166a0">567ef13</a> <a href="/external/github.com/kubernetes/klog/+/567ef13033a7916bdca02fd1b572b97fcc8166a0">Update to newer golang versions</a> <span class="CommitLog-author" title="davanum@gmail.com">by Davanum Srinivas</span> <span class="CommitLog-time" title="Wed Jun 02 23:55:30 2021">路 3 years, 6 months ago</span></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/external/github.com/kubernetes/klog/+/02ca14bed863fe45aa7544bbb0febef5db51163c">02ca14b</a> <a href="/external/github.com/kubernetes/klog/+/02ca14bed863fe45aa7544bbb0febef5db51163c">Merge pull request #238 from yuzhiquan/fix-nit-for-klog</a> <span class="CommitLog-author" title="k8s-ci-robot@users.noreply.github.com">by Kubernetes Prow Robot</span> <span class="CommitLog-time" title="Wed May 12 11:07:38 2021">路 3 years, 7 months ago</span> <a class="CommitLog-tagLabel" href="/external/github.com/kubernetes/klog/+/refs/tags/upstream/v2.9.0">upstream/v2.9.0</a></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/external/github.com/kubernetes/klog/+/6a9ef3fa9a1579c6ed170db139f5629bde0ba04e">6a9ef3f</a> <a href="/external/github.com/kubernetes/klog/+/6a9ef3fa9a1579c6ed170db139f5629bde0ba04e">fix typo</a> <span class="CommitLog-author" title="yuzhiquanlong@gmail.com">by yuzhiquan</span> <span class="CommitLog-time" title="Wed May 12 07:42:21 2021">路 3 years, 7 months ago</span></li><li class="CommitLog-item CommitLog-item--oneline"><a class="u-sha1 u-monospace CommitLog-sha1" href="/external/github.com/kubernetes/klog/+/4c0ac5a1c7d6f0b4f86c4c7b858b655e5267cd84">4c0ac5a</a> <a href="/external/github.com/kubernetes/klog/+/4c0ac5a1c7d6f0b4f86c4c7b858b655e5267cd84">Merge pull request #237 from yuzhiquan/fix-byte-array-display</a> <span class="CommitLog-author" title="k8s-ci-robot@users.noreply.github.com">by Kubernetes Prow Robot</span> <span class="CommitLog-time" title="Tue May 11 02:25:36 2021">路 3 years, 7 months ago</span></li></ol><nav class="LogNav"><a class="LogNav-next" href="/external/github.com/kubernetes/klog/+log">More »</a></nav><div class="doc RepoIndexDoc"><h1><a class="h" name="klog" href="#klog"><span></span></a>klog</h1><p>klog is a permanent fork of <a href="https://github.com/golang/glog">https://github.com/golang/glog</a>.</p><h2><a class="h" name="Why-was-klog-created" href="#Why-was-klog-created"><span></span></a><a class="h" name="why-was-klog-created" href="#why-was-klog-created"><span></span></a>Why was klog created?</h2><p>The decision to create klog was one that wasn't made lightly, but it was necessary due to some drawbacks that are present in <a href="https://github.com/golang/glog">glog</a>. Ultimately, the fork was created due to glog not being under active development; this can be seen in the glog README:</p><blockquote><p>The code in this repo [...] is not itself under development</p></blockquote><p>This makes us unable to solve many use cases without a fork. The factors that contributed to needing feature development are listed below:</p><ul><li><code class="code">glog</code> <a href="https://github.com/kubernetes/kubernetes/issues/61006">presents a lot “gotchas”</a> and introduces challenges in containerized environments, all of which aren't well documented.</li><li><code class="code">glog</code> doesn't provide an easy way to test logs, which detracts from the stability of software using it</li><li>A long term goal is to implement a logging interface that allows us to add context, change output format, etc.</li></ul><p>Historical context is available here:</p><ul><li><a href="https://github.com/kubernetes/kubernetes/issues/61006">https://github.com/kubernetes/kubernetes/issues/61006</a></li><li><a href="https://github.com/kubernetes/kubernetes/issues/70264">https://github.com/kubernetes/kubernetes/issues/70264</a></li><li><a href="https://groups.google.com/forum/#!msg/kubernetes-sig-architecture/wCWiWf3Juzs/hXRVBH90CgAJ">https://groups.google.com/forum/#!msg/kubernetes-sig-architecture/wCWiWf3Juzs/hXRVBH90CgAJ</a></li><li><a href="https://groups.google.com/forum/#!msg/kubernetes-dev/7vnijOMhLS0/1oRiNtigBgAJ">https://groups.google.com/forum/#!msg/kubernetes-dev/7vnijOMhLS0/1oRiNtigBgAJ</a></li></ul><hr /><h1><a class="h" name="How-to-use-klog" href="#How-to-use-klog"><span></span></a><a class="h" name="how-to-use-klog" href="#how-to-use-klog"><span></span></a>How to use klog</h1><ul><li>Replace imports for <code class="code">"github.com/golang/glog"</code> with <code class="code">"k8s.io/klog/v2"</code></li><li>Use <code class="code">klog.InitFlags(nil)</code> explicitly for initializing global flags as we no longer use <code class="code">init()</code> method to register the flags</li><li>You can now use <code class="code">log_file</code> instead of <code class="code">log_dir</code> for logging to a single file (See <code class="code">examples/log_file/usage_log_file.go</code>)</li><li>If you want to redirect everything logged using klog somewhere else (say syslog!), you can use <code class="code">klog.SetOutput()</code> method and supply a <code class="code">io.Writer</code>. (See <code class="code">examples/set_output/usage_set_output.go</code>)</li><li>For more logging conventions (See <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md">Logging Conventions</a>)</li></ul><p><strong>NOTE</strong>: please use the newer go versions that support semantic import versioning in modules, ideally go 1.11.4 or greater.</p><h3><a class="h" name="Coexisting-with-klog_v2" href="#Coexisting-with-klog_v2"><span></span></a><a class="h" name="coexisting-with-klog_v2" href="#coexisting-with-klog_v2"><span></span></a>Coexisting with klog/v2</h3><p>See <a href="+/HEAD/examples/coexist_klog_v1_and_v2">this example</a> to see how to coexist with both klog/v1 and klog/v2.</p><h3><a class="h" name="Coexisting-with-glog" href="#Coexisting-with-glog"><span></span></a><a class="h" name="coexisting-with-glog" href="#coexisting-with-glog"><span></span></a>Coexisting with glog</h3><p>This package can be used side by side with glog. <a href="+/HEAD/examples/coexist_glog/coexist_glog.go">This example</a> shows how to initialize and synchronize flags from the global <code class="code">flag.CommandLine</code> FlagSet. In addition, the example makes use of stderr as combined output by setting <code class="code">alsologtostderr</code> (or <code class="code">logtostderr</code>) to <code class="code">true</code>.</p><h2><a class="h" name="Community_discussion_contribution_and-support" href="#Community_discussion_contribution_and-support"><span></span></a><a class="h" name="community_discussion_contribution_and-support" href="#community_discussion_contribution_and-support"><span></span></a>Community, discussion, contribution, and support</h2><p>Learn how to engage with the Kubernetes community on the <a href="http://kubernetes.io/community/">community page</a>.</p><p>You can reach the maintainers of this project at:</p><ul><li><a href="https://kubernetes.slack.com/messages/klog">Slack</a></li><li><a href="https://groups.google.com/forum/#!forum/kubernetes-sig-architecture">Mailing List</a></li></ul><h3><a class="h" name="Code-of-conduct" href="#Code-of-conduct"><span></span></a><a class="h" name="code-of-conduct" href="#code-of-conduct"><span></span></a>Code of conduct</h3><p>Participation in the Kubernetes community is governed by the <a href="+/HEAD/code-of-conduct.md">Kubernetes Code of Conduct</a>.</p><hr /><h1><a class="h" name="glog" href="#glog"><span></span></a>glog</h1><p>Leveled execution logs for Go.</p><p>This is an efficient pure Go implementation of leveled logs in the manner of the open source C++ package <a href="https://github.com/google/glog">https://github.com/google/glog</a></p><p>By binding methods to booleans it is possible to use the log package without paying the expense of evaluating the arguments to the log. Through the -vmodule flag, the package also provides fine-grained control over logging at the file level.</p><p>The comment from glog.go introduces the ideas:</p><pre class="code">Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags. Basic examples: glog.Info("Prepare to repel boarders") glog.Fatalf("Initialization failed: %s", err) See the documentation for the V function for an explanation of these examples: if glog.V(2) { glog.Info("Starting transaction...") } glog.V(2).Infoln("Processed", nItems, "elements") </pre><p>The repository contains an open source version of the log package used inside Google. The master copy of the source lives inside Google, not here. The code in this repo is for export only and is not itself under development. Feature requests will be ignored.</p><p>Send bug reports to <a href="mailto:golang-nuts@googlegroups.com">golang-nuts@googlegroups.com</a>.</p></div></div></div></div> <!-- Container --></div> <!-- Site-content --><footer class="Site-footer"><div class="Footer"><span class="Footer-poweredBy">Powered by <a href="https://gerrit.googlesource.com/gitiles/">Gitiles</a>| <a href="https://policies.google.com/privacy">Privacy</a>| <a href="https://policies.google.com/terms">Terms</a></span><span class="Footer-formats"><a class="u-monospace Footer-formatsItem" href="?format=TEXT">txt</a> <a class="u-monospace Footer-formatsItem" href="?format=JSON">json</a></span></div></footer></body></html><script nonce="HZ4vB9JZdFqe92-dTeJyZg">{let f = document.getElementById("clone-repo-input"); f.onclick = () => {f.focus(); if (f.selectionStart === f.selectionEnd) {f.select();}};}</script>