Bumps [actions/setup-go](https://github.com/actions/setup-go) from 5.5.0 to 6.1.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/actions/setup-go/releases">actions/setup-go's releases</a>.</em></p> <blockquote> <h2>v6.1.0</h2> <h2>What's Changed</h2> <h3>Enhancements</h3> <ul> <li>Fall back to downloading from go.dev/dl instead of storage.googleapis.com/golang by <a href="https://github.com/nicholasngai"><code>@nicholasngai</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/665">actions/setup-go#665</a></li> <li>Add support for .tool-versions file and update workflow by <a href="https://github.com/priya-kinthali"><code>@priya-kinthali</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/673">actions/setup-go#673</a></li> <li>Add comprehensive breaking changes documentation for v6 by <a href="https://github.com/mahabaleshwars"><code>@mahabaleshwars</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/674">actions/setup-go#674</a></li> </ul> <h3>Dependency updates</h3> <ul> <li>Upgrade eslint-config-prettier from 10.0.1 to 10.1.8 and document breaking changes in v6 by <a href="https://github.com/dependabot"><code>@dependabot</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/617">actions/setup-go#617</a></li> <li>Upgrade actions/publish-action from 0.3.0 to 0.4.0 by <a href="https://github.com/dependabot"><code>@dependabot</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/641">actions/setup-go#641</a></li> <li>Upgrade semver and <code>@types/semver</code> by <a href="https://github.com/dependabot"><code>@dependabot</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/652">actions/setup-go#652</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/nicholasngai"><code>@nicholasngai</code></a> made their first contribution in <a href="https://redirect.github.com/actions/setup-go/pull/665">actions/setup-go#665</a></li> <li><a href="https://github.com/priya-kinthali"><code>@priya-kinthali</code></a> made their first contribution in <a href="https://redirect.github.com/actions/setup-go/pull/673">actions/setup-go#673</a></li> <li><a href="https://github.com/mahabaleshwars"><code>@mahabaleshwars</code></a> made their first contribution in <a href="https://redirect.github.com/actions/setup-go/pull/674">actions/setup-go#674</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/actions/setup-go/compare/v6...v6.1.0">https://github.com/actions/setup-go/compare/v6...v6.1.0</a></p> <h2>v6.0.0</h2> <h2>What's Changed</h2> <h3>Breaking Changes</h3> <ul> <li>Improve toolchain handling to ensure more reliable and consistent toolchain selection and management by <a href="https://github.com/matthewhughes934"><code>@matthewhughes934</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/460">actions/setup-go#460</a></li> <li>Upgrade Nodejs runtime from node20 to node 24 by <a href="https://github.com/salmanmkc"><code>@salmanmkc</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/624">actions/setup-go#624</a></li> </ul> <p>Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. <a href="https://github.com/actions/runner/releases/tag/v2.327.1">See Release Notes</a></p> <h3>Dependency Upgrades</h3> <ul> <li>Upgrade <code>@types/jest</code> from 29.5.12 to 29.5.14 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/589">actions/setup-go#589</a></li> <li>Upgrade <code>@actions/tool-cache</code> from 2.0.1 to 2.0.2 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/591">actions/setup-go#591</a></li> <li>Upgrade <code>@typescript-eslint/parser</code> from 8.31.1 to 8.35.1 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/590">actions/setup-go#590</a></li> <li>Upgrade undici from 5.28.5 to 5.29.0 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/594">actions/setup-go#594</a></li> <li>Upgrade typescript from 5.4.2 to 5.8.3 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/538">actions/setup-go#538</a></li> <li>Upgrade eslint-plugin-jest from 28.11.0 to 29.0.1 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/603">actions/setup-go#603</a></li> <li>Upgrade <code>form-data</code> to bring in fix for critical vulnerability by <a href="https://github.com/matthewhughes934"><code>@matthewhughes934</code></a> in <a href="https://redirect.github.com/actions/setup-go/pull/618">actions/setup-go#618</a></li> <li>Upgrade actions/checkout from 4 to 5 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/actions/setup-go/pull/631">actions/setup-go#631</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/matthewhughes934"><code>@matthewhughes934</code></a> made their first contribution in <a href="https://redirect.github.com/actions/setup-go/pull/618">actions/setup-go#618</a></li> <li><a href="https://github.com/salmanmkc"><code>@salmanmkc</code></a> made their first contribution in <a href="https://redirect.github.com/actions/setup-go/pull/624">actions/setup-go#624</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/actions/setup-go/compare/v5...v6.0.0">https://github.com/actions/setup-go/compare/v5...v6.0.0</a></p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href=" |
||
|---|---|---|
| .chainguard | ||
| .github | ||
| examples | ||
| gcp | ||
| slag | ||
| slogtest | ||
| .gitignore | ||
| example_test.go | ||
| go.mod | ||
| go.sum | ||
| handler.go | ||
| handler_test.go | ||
| LICENSE | ||
| log.go | ||
| logger.go | ||
| logger_test.go | ||
| README.md | ||
👞 clog
Context-aware slog
slog was added in Go 1.21, so using this requires Go 1.21 or later.
Usage
Context Logger
The context Logger can be used to use Loggers from the context. This is sometimes preferred over the Context Handler, since this can make it easier to use different loggers in different contexts (e.g. testing).
This approach is heavily inspired by
knative.dev/pkg/logging, but with zero dependencies outside the standard library (compare with pkg/logging's deps).
package main
import (
"context"
"log/slog"
"github.com/chainguard-dev/clog"
)
func main() {
// One-time setup
log := clog.New(slog.Default().Handler()).With("a", "b")
ctx := clog.WithLogger(context.Background(), log)
f(ctx)
}
func f(ctx context.Context) {
// Grab logger from context and use.
log := clog.FromContext(ctx)
log.Info("in f")
// Add logging context and pass on.
ctx = clog.WithLogger(ctx, log.With("f", "hello"))
g(ctx)
}
func g(ctx context.Context) {
// Grab logger from context and use.
log := clog.FromContext(ctx)
log.Info("in g")
// Package level context loggers are also aware
clog.ErrorContext(ctx, "asdf")
}
$ go run .
2009/11/10 23:00:00 INFO in f a=b
2009/11/10 23:00:00 INFO in g a=b f=hello
2009/11/10 23:00:00 ERROR asdf a=b f=hello
Testing
The slogtest package provides utilities to make it easy to create loggers that
will use the native testing logging.
func TestFoo(t *testing.T) {
ctx := slogtest.TestContextWithLogger(t)
for _, tc := range []string{"a", "b"} {
t.Run(tc, func(t *testing.T) {
clog.FromContext(ctx).Infof("hello world")
})
}
}
$ go test -v ./examples/logger
=== RUN TestLog
=== RUN TestLog/a
=== NAME TestLog
slogtest.go:20: time=2023-12-12T18:42:53.020-05:00 level=INFO msg="hello world"
=== RUN TestLog/b
=== NAME TestLog
slogtest.go:20: time=2023-12-12T18:42:53.020-05:00 level=INFO msg="hello world"
--- PASS: TestLog (0.00s)
--- PASS: TestLog/a (0.00s)
--- PASS: TestLog/b (0.00s)
PASS
ok github.com/chainguard-dev/clog/examples/logger
Context Handler
The context Handler can be used to insert values from the context.
func init() {
slog.SetDefault(slog.New(clog.NewHandler(slog.NewTextHandler(os.Stdout, nil))))
}
func main() {
ctx := context.Background()
ctx = clog.WithValues(ctx, "foo", "bar")
// Use slog package directly
slog.InfoContext(ctx, "hello world", slog.Bool("baz", true))
// glog / zap style (note: can't pass additional attributes)
clog.ErrorContextf(ctx, "hello %s", "world")
}
$ go run .
time=2009-11-10T23:00:00.000Z level=INFO msg="hello world" baz=true foo=bar
time=2009-11-10T23:00:00.000Z level=ERROR msg="hello world" foo=bar
Google Cloud Platform support
This package also provides a GCP-optimized JSON handler for structured logging and trace attribution.
See ./gcp/README.md for details.