Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for PR #280, refactoring, textlogger, unit test #287

Merged
merged 12 commits into from Feb 14, 2022

Commits on Feb 14, 2022

  1. README.md: clarify API stability

    We need the ability to make experimental changes without new definitions
    immediately becoming part of the stable v2 API.
    pohly committed Feb 14, 2022
    Copy the full SHA
    10888e7 View commit details
    Browse the repository at this point in the history
  2. test: unified testing of structured logging

    The new test cases are applied to structured logging calls in klog and the
    stand-alone klogr logger with output through klog. The output is expected to be
    the same.
    pohly committed Feb 14, 2022
    Copy the full SHA
    7cad178 View commit details
    Browse the repository at this point in the history
  3. test: add systematic testing of all klog functions

    klog has a lot of functions, but not all of them are covered with unit
    tests. Only a few check stack unwinding.
    
    This new test is designed to:
    - check stack unwinding for all functions
    - check the difference between fmt.Print and fmt.Println (only the
      latter inserts spaces between strings)
    - check the output with and without a Logger
    
    This therefore covers bugs in kubernetes#280:
    - depth was not passed on to Logger
    - ErrorlnDepth and WarninglnDepth used fmt.Print instead of fmt.Println
    pohly committed Feb 14, 2022
    Copy the full SHA
    5a670a2 View commit details
    Browse the repository at this point in the history
  4. fix for off-by-one stack unwinding

    kubernetes#280 turned println and printf into
    wrapper functions, but the underlying *Depth functions kept passing the same 0
    depth to l.output and thus any logr.Logger.
    
    That off-by-one error broke JSON tests in Kubernetes, luckily well before any
    of the PR went into a release. It would be nice to have regression testing for
    this in klog, but we cannot depend on a Logger which does stack unwinding in
    the code, so the only thing that could be done is some kind of GitHub action
    which combines klog with some external logger.
    
    The depth=1 in println is also not covered by unit tests, but seems to be
    correct based on the JSON tests.
    pohly committed Feb 14, 2022
    Copy the full SHA
    51711a3 View commit details
    Browse the repository at this point in the history
  5. fix new *lnDepth functions

    kubernetes#280 added several new functions and
    didn't quite get the print vs println difference right: the corresponding
    non-Depth functions use fmt.Println and the Depth versions should do the same.
    pohly committed Feb 14, 2022
    Copy the full SHA
    5deb037 View commit details
    Browse the repository at this point in the history
  6. test: benchmark for V

    The implementation of V is performance critical: it may get called frequently
    on hot code paths and will be responsible for all of the logging overhead when
    the log messages then do not need to be formatted.
    pohly committed Feb 14, 2022
    Copy the full SHA
    0893658 View commit details
    Browse the repository at this point in the history
  7. internal: stand-alone implementation of -v and -verbose

    This will be needed for Logger implementations that want to emulate the
    traditional verbosity check in klog.
    
    The original code in klog.go intentionally doesn't get modified, for
    two reasons:
    - avoid the risk of regressions
    - an attempt to do so showed that V became slower (extra calls, more
      parameters, etc.)
    pohly committed Feb 14, 2022
    Copy the full SHA
    ec9f867 View commit details
    Browse the repository at this point in the history
  8. internal: move key/value handling into stand-alone package

    This makes it possible to reuse the klog output formatting in logr.Logger
    implementations.
    pohly committed Feb 14, 2022
    Copy the full SHA
    69f6111 View commit details
    Browse the repository at this point in the history
  9. split out buffer helpers and severity definition

    This will enable writing Logger implementations which reproduce the traditional
    klog header.
    pohly committed Feb 14, 2022
    Copy the full SHA
    c734dc7 View commit details
    Browse the repository at this point in the history
  10. klogr: report missing values with "(MISSING)"

    klogr had a special value for a missing value in a key/value pair, so the
    intention probably was to use that as replacement, the same way as klog does
    it. But because of a bug in the code which removed duplicates, it treated a
    missing value like nil. Now the behavior is consistent with klog.
    pohly committed Feb 14, 2022
    Copy the full SHA
    cda3be7 View commit details
    Browse the repository at this point in the history
  11. klogr: improve handling of missing value in WithValues

    This is invalid:
       logger.WithValue("keyWithoutValue").WithValue("anotherKeyWithoutValue")
    
    Because it concatenated key/values without checking, klogr treated this like:
       logger.WithValue("keyWithoutValue", "anotherKeyWithoutValue")
    
    Now the parameters are checked and a "(MISSING)" is appended as in the other
    cases where a missing value is detected.
    pohly committed Feb 14, 2022
    Copy the full SHA
    5938b0a View commit details
    Browse the repository at this point in the history
  12. textlogger: add logger which emulates the traditional output

    In contrast to klogr, the formatting and printing is handled entirely
    by this logger without depending on klog.go.
    
    The intention is to use this in two ways:
    - for testing of SetLogger
    - as simpler text logger in Kubernetes for contextual logging
    pohly committed Feb 14, 2022
    Copy the full SHA
    71ac98f View commit details
    Browse the repository at this point in the history