From 0ba4b4ed3d12ffc3c28926f67dcd7d5261389a83 Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Tue, 30 Jun 2026 20:27:14 +0000 Subject: [PATCH] go: upgrade to Go 1.26.4 and run go fix ./... --- go.mod | 2 +- .../sinkcores/sentrycore/integration_test.go | 20 +++++++++---------- logger_test.go | 8 ++++---- logr/go.mod | 2 +- logtest/logtest.go | 10 +++------- logtest/logtest_test.go | 2 +- sinks_output.go | 2 +- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index bfb584b..1164c87 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/sourcegraph/log -go 1.25.9 +go 1.26.4 require ( github.com/cockroachdb/errors v1.9.1 diff --git a/internal/sinkcores/sentrycore/integration_test.go b/internal/sinkcores/sentrycore/integration_test.go index 5e54ee5..18a827f 100644 --- a/internal/sinkcores/sentrycore/integration_test.go +++ b/internal/sinkcores/sentrycore/integration_test.go @@ -141,13 +141,13 @@ func TestWithTrace(t *testing.T) { } func TestFields(t *testing.T) { - assertEventLogCtx := func(t *testing.T, tr *sentrycore.TransportMock, cb func(map[string]interface{})) { + assertEventLogCtx := func(t *testing.T, tr *sentrycore.TransportMock, cb func(map[string]any)) { assert.Len(t, tr.Events(), 1) if len(tr.Events()) < 1 { t.FailNow() } e := tr.Events()[0] - assert.IsType(t, map[string]interface{}{}, e.Contexts["log"]) + assert.IsType(t, map[string]any{}, e.Contexts["log"]) cb(tr.Events()[0].Contexts["log"]) } e := errors.New("test error") @@ -156,7 +156,7 @@ func TestFields(t *testing.T) { logger, tr, sync := newTestLogger(t) logger.With(log.Int("int", 4)).Error("msg", log.Error(e)) sync() - assertEventLogCtx(t, tr, func(ctx map[string]interface{}) { + assertEventLogCtx(t, tr, func(ctx map[string]any) { assert.Equal(t, int64(4), ctx["int"]) }) }) @@ -164,7 +164,7 @@ func TestFields(t *testing.T) { logger, tr, sync := newTestLogger(t) logger.With(log.Int64("int", 4)).Error("msg", log.Error(e)) sync() - assertEventLogCtx(t, tr, func(ctx map[string]interface{}) { + assertEventLogCtx(t, tr, func(ctx map[string]any) { assert.Equal(t, int64(4), ctx["int"]) }) }) @@ -172,7 +172,7 @@ func TestFields(t *testing.T) { logger, tr, sync := newTestLogger(t) logger.With(log.String("string", "foo")).Error("msg", log.Error(e)) sync() - assertEventLogCtx(t, tr, func(ctx map[string]interface{}) { + assertEventLogCtx(t, tr, func(ctx map[string]any) { assert.Equal(t, "foo", ctx["string"]) }) }) @@ -180,8 +180,8 @@ func TestFields(t *testing.T) { logger, tr, sync := newTestLogger(t) logger.With(log.Object("object", log.String("string", "foo"), log.Int("int", 4))).Error("msg", log.Error(e)) sync() - assertEventLogCtx(t, tr, func(ctx map[string]interface{}) { - assert.Equal(t, map[string]interface{}{"int": int64(4), "string": "foo"}, ctx["object"]) + assertEventLogCtx(t, tr, func(ctx map[string]any) { + assert.Equal(t, map[string]any{"int": int64(4), "string": "foo"}, ctx["object"]) }) }) } @@ -223,12 +223,12 @@ func TestConcurrentLogging(t *testing.T) { var wg sync.WaitGroup wg.Add(10) f := func() { - for i := 0; i < 10; i++ { + for range 10 { logger.With(log.Error(e)).Error("msg") } wg.Done() } - for i := 0; i < 10; i++ { + for range 10 { go f() } wg.Wait() @@ -245,7 +245,7 @@ func TestNeverBlock(t *testing.T) { c := sentrycore.NewCore(hub) c.Stop() - for i := 0; i < 2048; i++ { + for range 2048 { c.Write(zapcore.Entry{Level: zapcore.ErrorLevel, Message: "should not block"}, []zapcore.Field{log.Error(e)}) } } diff --git a/logger_test.go b/logger_test.go index 3bfd852..c80d74d 100644 --- a/logger_test.go +++ b/logger_test.go @@ -51,22 +51,22 @@ func TestLogger(t *testing.T) { } // Nested fields should be in attributes - assert.Equal(t, map[string]interface{}{ + assert.Equal(t, map[string]any{ "some": "field", "hello": "world", }, logs[1].Fields["Attributes"]) // TraceId should be in root, everything else in attributes assert.Equal(t, "1234abcde", logs[2].Fields["TraceId"]) - assert.Equal(t, map[string]interface{}{ + assert.Equal(t, map[string]any{ "some": "field", "world": "hello", }, logs[2].Fields["Attributes"]) // Nested fields should be in attributes - assert.Equal(t, map[string]interface{}{ + assert.Equal(t, map[string]any{ "some": "field", - "object": map[string]interface{}{ + "object": map[string]any{ "field1": "value", "field2": "value", }, diff --git a/logr/go.mod b/logr/go.mod index bb9a72a..7c7c21c 100644 --- a/logr/go.mod +++ b/logr/go.mod @@ -1,6 +1,6 @@ module github.com/sourcegraph/log/logr -go 1.19 +go 1.26.4 replace github.com/sourcegraph/log => ../ diff --git a/logtest/logtest.go b/logtest/logtest.go index d7b8ccc..3c32bf6 100644 --- a/logtest/logtest.go +++ b/logtest/logtest.go @@ -2,6 +2,7 @@ package logtest import ( "flag" + "slices" "sync" "testing" "time" @@ -68,7 +69,7 @@ type CapturedLog struct { Scope string Level log.Level Message string - Fields map[string]interface{} + Fields map[string]any } type CapturedLogs []CapturedLog @@ -96,12 +97,7 @@ func (cl CapturedLogs) Filter(condition func(l CapturedLog) bool) CapturedLogs { // Contains asserts that at least one entry matching the condition exists in the captured // logs. func (cl CapturedLogs) Contains(condition func(l CapturedLog) bool) bool { - for _, l := range cl { - if condition(l) { - return true - } - } - return false + return slices.ContainsFunc(cl, condition) } type LoggerOptions struct { diff --git a/logtest/logtest_test.go b/logtest/logtest_test.go index ea80598..c52b44c 100644 --- a/logtest/logtest_test.go +++ b/logtest/logtest_test.go @@ -21,7 +21,7 @@ func TestExport(t *testing.T) { assert.Equal(t, "hello world", logs[0].Message) // retains the message // In dev mode, attributes are not added, but custom fields are retained - assert.Equal(t, map[string]interface{}{"key": "value"}, logs[0].Fields) + assert.Equal(t, map[string]any{"key": "value"}, logs[0].Fields) // We can filter for entries assert.Len(t, logs.Filter(func(l CapturedLog) bool { diff --git a/sinks_output.go b/sinks_output.go index 9e46dc8..0f696a5 100644 --- a/sinks_output.go +++ b/sinks_output.go @@ -76,7 +76,7 @@ func parseSamplingConfig() (config zap.SamplingConfig, err error) { func parseOverrides() ([]outputcore.Override, error) { raw := os.Getenv(EnvLogScopeLevel) var overrides []outputcore.Override - for _, kv := range strings.Split(raw, ",") { + for kv := range strings.SplitSeq(raw, ",") { if kv == "" { continue }