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

slog support + logr 1.3.0 update #384

Merged
merged 2 commits into from
Oct 31, 2023
Merged

slog support + logr 1.3.0 update #384

merged 2 commits into from
Oct 31, 2023

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