Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes/klog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.100.1
Choose a base ref
...
head repository: kubernetes/klog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.110.1
Choose a head ref
  • 20 commits
  • 56 files changed
  • 4 contributors

Commits on May 17, 2023

  1. fix: SetLogger via klog.SetLogger will output an unexpected newline

    klog always adds a newline to the msg. klog will work fine without klog.
    
    Set logr with klog.SetLogger, and klog will also pass the msg with the newline added to logr, which will result in an accidental newline being added.
    
    step1: klog.Info("hello world")
    step2: msg = msg + "\n"
    step3: stdout.W(msg) or logr.Info(msg[:len(msg)-1])
    
    fix #370
    
    Signed-off-by: aimuz <mr.imuz@gmail.com>
    aimuz committed May 17, 2023
    Configuration menu
    Copy the full SHA
    1e2789b View commit details
    Browse the repository at this point in the history

Commits on May 20, 2023

  1. Merge pull request #378 from aimuz/fix-370

    fix: SetLogger via klog.SetLogger will output an unexpected newline
    k8s-ci-robot authored May 20, 2023
    Configuration menu
    Copy the full SHA
    5ac9b76 View commit details
    Browse the repository at this point in the history

Commits on May 27, 2023

  1. resolve comments warning

    Signed-off-by: lowang_bh <lhui_wang@163.com>
    lowang-bh committed May 27, 2023
    Configuration menu
    Copy the full SHA
    6c35c6a View commit details
    Browse the repository at this point in the history

Commits on May 30, 2023

  1. Merge pull request #379 from lowang-bh/fixWarning

    resolve comments warning
    k8s-ci-robot authored May 30, 2023
    Configuration menu
    Copy the full SHA
    ff82b97 View commit details
    Browse the repository at this point in the history

Commits on Jun 1, 2023

  1. fix golangci-lint issues

    golangci-lint v1.52.2 in its default configuration pointed out several issues
    that are worth fixing:
    
        internal/verbosity/verbosity_test.go:26:18: Error return value of `vs.verbosity.Set` is not checked (errcheck)
        	vs.verbosity.Set("2")
        	                ^
        internal/verbosity/verbosity_test.go:41:16: Error return value of `vs.vmodule.Set` is not checked (errcheck)
        	vs.vmodule.Set("verbosity_test=2")
        	              ^
        internal/verbosity/verbosity_test.go:84:16: Error return value of `vs.vmodule.Set` is not checked (errcheck)
        	vs.vmodule.Set(pat)
        	              ^
        internal/verbosity/verbosity.go:291:2: S1017: should replace this if statement with an unconditional strings.TrimSuffix (gosimple)
        	if strings.HasSuffix(file, ".go") {
        	^
        textlogger/options.go:140:19: Error return value of `(flag.Value).Set` is not checked (errcheck)
        	c.Verbosity().Set(strconv.FormatInt(int64(c.co.verbosityDefault), 10))
        	                 ^
        textlogger/textlogger.go:137:26: Error return value of `l.config.co.output.Write` is not checked (errcheck)
        	l.config.co.output.Write(b.Bytes())
        	                        ^
        textlogger/textlogger.go:141:26: Error return value of `l.config.co.output.Write` is not checked (errcheck)
        	l.config.co.output.Write(data)
        	                        ^
        ktesting/options.go:163:18: Error return value of `(flag.Value).Set` is not checked (errcheck)
        	c.vstate.V().Set(strconv.FormatInt(int64(c.co.verbosityDefault), 10))
        	                ^
        klogr/calldepth-test/call_depth_main_test.go:21:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("v", "10")
        	                    ^
        klogr/calldepth-test/call_depth_main_test.go:22:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("skip_headers", "false")
        	                    ^
        klogr/calldepth-test/call_depth_main_test.go:23:22: Error return value of `flag.CommandLine.Set` is not checked (errcheck)
        	flag.CommandLine.Set("logtostderr", "false")
        	                    ^
        klog.go:903:34: Error return value of `(io.Writer).Write` is not checked (errcheck)
        			l.file[severity.InfoLog].Write(data)
        			                              ^
        klog.go:913:20: Error return value of `(io.Writer).Write` is not checked (errcheck)
        				l.file[s].Write(data)
        				               ^
        klog.go:917:37: Error return value of `(io.Writer).Write` is not checked (errcheck)
        					l.file[severity.FatalLog].Write(data)
        					                               ^
        klog.go:952:12: Error return value of `f.Write` is not checked (errcheck)
        				f.Write(trace)
        				       ^
        klog.go:1208:13: Error return value of `file.Sync` is not checked (errcheck)
        			file.Sync()  // ignore error
        			         ^
        klog_file.go:113:14: Error return value of `os.Symlink` is not checked (errcheck)
        			os.Symlink(name, symlink) // ignore err
        			          ^
        klog_test.go:328:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("2")
        	                     ^
        klog_test.go:343:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set("klog_test=2")
        	                   ^
        klog_test.go:367:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set("notthisfile=2")
        	                   ^
        klog_test.go:459:21: Error return value of `logging.vmodule.Set` is not checked (errcheck)
        	logging.vmodule.Set(pat)
        	                   ^
        klog_test.go:807:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("0")
        	                     ^
        klog_test.go:878:9: Error return value of `fs1.Set` is not checked (errcheck)
        	fs1.Set("log_dir", "/test1")
        	       ^
        klog_test.go:879:9: Error return value of `fs1.Set` is not checked (errcheck)
        	fs1.Set("log_file_max_size", "1")
        	       ^
        klog_test.go:885:9: Error return value of `fs2.Set` is not checked (errcheck)
        	fs2.Set("log_file_max_size", "2048")
        	       ^
        klog_test.go:1173:23: Error return value of `logging.verbosity.Set` is not checked (errcheck)
        	logging.verbosity.Set("2")
        	                     ^
        klogr.go:35:2: field `level` is unused (unused)
        	level     int
        	^
        klog.go:1287:2: S1017: should replace this if statement with an unconditional strings.TrimSuffix (gosimple)
        	if strings.HasSuffix(file, ".go") {
        	^
        klog.go:521:2: S1001: should use copy(to, from) instead of a loop (gosimple)
        	for i := range s.vmodule.filter {
        	^
        klog_test.go:79:2: S1001: should copy arrays using assignment instead of using a loop (gosimple)
        	for i, w := range writers {
        	^
        klogr/klogr.go:118:16: Error return value of `encoder.Encode` is not checked (errcheck)
        	encoder.Encode(value)
        	              ^
        klogr/klogr_test.go:208:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("skip_headers", "true")
        	      ^
        klogr/klogr.go:119:27: S1030: should use buffer.String() instead of string(buffer.Bytes()) (gosimple)
        	return strings.TrimSpace(string(buffer.Bytes()))
        	                         ^
        ktesting/testinglogger_test.go:176:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("alsologtostderr", "false")
        	      ^
        ktesting/testinglogger_test.go:177:8: Error return value of `fs.Set` is not checked (errcheck)
        	fs.Set("logtostderr", "false")
        	      ^
        internal/buffer/buffer.go:40:2: field `next` is unused (unused)
        	next *Buffer
        	^
        internal/clock/clock.go:122:9: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck)
        	return time.Tick(d)
        	       ^
        exit_test.go:31:16: Error return value of `flag.Set` is not checked (errcheck)
        	defer flag.Set("skip_headers", "false")
        	              ^
        format_test.go:46:5: S1003: should use strings.Contains(str, "kind is config") instead (gosimple)
        	if strings.Index(str, "kind is config") >= 0 {
        	   ^
    pohly committed Jun 1, 2023
    Configuration menu
    Copy the full SHA
    a4f9060 View commit details
    Browse the repository at this point in the history

Commits on Jun 13, 2023

  1. stderrthreshold: fix flag comment

    The code is so that the -stderrthreshold gets ignored when
    -alsologtostderr=true.
    pohly committed Jun 13, 2023
    Configuration menu
    Copy the full SHA
    3838dbc View commit details
    Browse the repository at this point in the history
  2. Merge pull request #376 from pohly/stderr-threshold-docs

    stderrthreshold: fix flag comment
    k8s-ci-robot authored Jun 13, 2023
    Configuration menu
    Copy the full SHA
    6632ba5 View commit details
    Browse the repository at this point in the history

Commits on Oct 23, 2023

  1. enable "go vet" checks for parameters

    Adding some dead code which calls fmt.Sprintf/Sprint/Sprintln makes "go vet"
    recognize what kind of parameters the unstructured klog calls
    take (https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/printf#hdr-Analyzer_printf).
    
    Then it can report incorrect calls like:
    
        klog.Infof("%s") // k8s.io/klog/v2.Infof format %s reads arg #1, but call has 0 args
        klog.Info("%s", "world") // k8s.io/klog/v2.Info call has possible formatting directive %s
    
    The same does not work for structured calls like klog.InfoS. logcheck needs to
    be used for those.
    pohly committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    b394f4b View commit details
    Browse the repository at this point in the history
  2. testing: bump Go version matrix

    Testing with Go 1.17 gets removed because it does not support "go mod vendor
    -o" and is out of support.
    pohly committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    6af4ad1 View commit details
    Browse the repository at this point in the history
  3. Merge pull request #390 from pohly/go-vet-print

    enable "go vet" checks for parameters
    k8s-ci-robot authored Oct 23, 2023
    Configuration menu
    Copy the full SHA
    61b308a View commit details
    Browse the repository at this point in the history

Commits on Oct 26, 2023

  1. promote experimental code to stable

    ktesting is heavily used in Kubernetes already for testing. The test package is
    also used. The textlogger is not used that much yet because it was still
    experimental (and thus no replacement for normal klog), but it's simple and
    unlikely to need any breaking API changes.
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    18cdd3a View commit details
    Browse the repository at this point in the history
  2. Merge pull request #392 from pohly/promote-experimental

    promote experimental code to stable
    k8s-ci-robot authored Oct 26, 2023
    Configuration menu
    Copy the full SHA
    edee20c View commit details
    Browse the repository at this point in the history
  3. fix revive issues

    In golangci-lint and upstream, revive has replaced golint because golint is no
    longer maintained. revive finds some more issues that need to be fixed before
    it can be used:
    
        ktesting/testinglogger.go:81:20: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
        func (n NopTL) Log(args ...interface{}) {}
                           ^
        klogr/klogr_test.go:23:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := func() logr.Logger {
        		switch format {
        		case formatNew:
        			return New()
        		case formatDefault:
        			return NewWithOptions()
        		default:
        			return NewWithOptions(WithFormat(Format(format)))
        		}
        	}
        internal/clock/testing/fake_clock.go:261:29: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) After(d time.Duration) <-chan time.Time {
                                    ^
        internal/clock/testing/fake_clock.go:267:32: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) NewTimer(d time.Duration) clock.Timer {
                                       ^
        internal/clock/testing/fake_clock.go:273:33: unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
        func (*IntervalClock) AfterFunc(d time.Duration, f func()) clock.Timer {
                                        ^
        textlogger/textlogger.go:148:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := *l
        	^
        textlogger/textlogger.go:157:2: redefines-builtin-id: redefinition of the built-in function new (revive)
        	new := *l
        	^
        textlogger/textlogger.go:91:24: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *tlogger) Info(level int, msg string, kvList ...interface{}) {
                               ^
        klog_test.go:2204:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
        	copy := settings.deepCopy()
        	^
        klog_test.go:95:48: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
        func contains(s severity.Severity, str string, t *testing.T) bool {
                                                       ^
        klog_test.go:378:28: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
        func TestSetOutputDataRace(t *testing.T) {
                                   ^
        klog_test.go:1807:25: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Info(level int, msg string, keysAndValues ...interface{}) {
                                ^
        klog_test.go:1828:25: unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Init(info logr.RuntimeInfo)             {}
                                ^
        klog_test.go:1829:28: unused-parameter: parameter 'level' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) Enabled(level int) bool                 { return true }
                                   ^
        klog_test.go:1833:34: unused-parameter: parameter 'depth' seems to be unused, consider removing or renaming it as _ (revive)
        func (l *testLogr) WithCallDepth(depth int) logr.LogSink   { return l }
                                         ^
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    ef25537 View commit details
    Browse the repository at this point in the history
  4. github: run golangci-lint via action

    The main advantage is that issues get posted as annotations, which makes them
    easier to find when looking at a diff for a PR.
    
    While at it, golangci-lint gets invoked so that it runs in its default
    configuration plus the linters that were enabled explicitly before (misspell,
    gofmt, revive as replacement for golint).
    
    It also gets applied to the examples package.
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    1a0dfc5 View commit details
    Browse the repository at this point in the history
  5. Merge pull request #380 from pohly/golangci-lint-action

    golangci-lint action
    k8s-ci-robot authored Oct 26, 2023
    Configuration menu
    Copy the full SHA
    b588475 View commit details
    Browse the repository at this point in the history
  6. output: handle WithName like zapr does

    Previously, all names set via `WithNames` were concatenated with / and added to
    the main message string as a `<names>: <msg>` prefix. Now klog in all of its
    incarnations (internal logger in klog, klogr, textlogger) behaves like zapr and
    adds a "logger" key with the names concatenated by a dot as value.
    
    The main advantage, besides consistency, is that code which does a full string
    match against some message string still works even when contextual logging is
    enabled and `WithName` is used, at least as long as that code doesn't also
    match all key/value pairs.
    pohly committed Oct 26, 2023
    Configuration menu
    Copy the full SHA
    009a04a View commit details
    Browse the repository at this point in the history
  7. Merge pull request #391 from pohly/with-name-output

    output: handle WithName like zapr does
    k8s-ci-robot authored Oct 26, 2023
    Configuration menu
    Copy the full SHA
    02e7b69 View commit details
    Browse the repository at this point in the history

Commits on Oct 27, 2023

  1. update to logr 1.3.0

    LogSink.Enabled is sensitive to stack unwinding. logr v1.2.0  got this wrong
    by calling LogSink.Enabled at different depths for Logger.Info and
    Logger.Enabled, therefore this test fails with that version.
    
    logr v1.3.0 changes the behavior to the more sane "LogSink.Enabled needs to
    skip one level, regardless where it is called". The Discard log sink
    implementation changed such that a discard logger doesn't have a sink at all
    anymore. Go < 1.18 is no longer supported by logr.
    pohly committed Oct 27, 2023
    Configuration menu
    Copy the full SHA
    cc856bb View commit details
    Browse the repository at this point in the history

Commits on Oct 30, 2023

  1. add slog support

    When compiled with Go >= 1.21, special support for log/slog gets enabled
    automatically:
    
    - The formatting of key/value pairs supports slog.Value and slog.LogValuer,
      regardless of where those come from.
    - A slog.GroupValue is formatted as a JSON object.
    - The logger returned by klog.Background() and the textlogger
      support usage as a backend for the slog API, via slogr.NewSlogHandler,
      with builtin support for handling a slog.Record. However, -vmodule
      does not work when called like that because stack unwinding during
      the Enabled check finds the wrong source code.
    - KObj (= ObjectRef) and the type behind KObjSlice support the
      slog.LogValuer interface and thus get formatted properly by slog backends.
    
    The klogr package doesn't get updated. It shouldn't be used anymore. To make
    that clearer, it gets marked as "deprecated".
    
    Examples demonstrate the resulting output. That output has to be exactly
    the same when used as test, so pid and time get set to fixed values.
    pohly committed Oct 30, 2023
    Configuration menu
    Copy the full SHA
    44eadc3 View commit details
    Browse the repository at this point in the history

Commits on Oct 31, 2023

  1. Merge pull request #384 from pohly/slog

    slog support + logr 1.3.0 update
    k8s-ci-robot authored Oct 31, 2023
    Configuration menu
    Copy the full SHA
    e3f75b8 View commit details
    Browse the repository at this point in the history
Loading