From 2fd0c1f9ecc418cff261824ed93aaaa949efa822 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 4 Apr 2024 12:12:09 +0300 Subject: [PATCH 1/2] update ling and go version --- .drone.yml | 4 ++-- bench_test.go | 2 ++ example/log.go | 2 +- field/encoder.go | 1 + middleware.go | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index f49d33f..b873675 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: logger steps: - name: test - image: golang:1.21.5 + image: golang:1.22 volumes: - name: deps path: /go/src/mod @@ -13,7 +13,7 @@ steps: - go test - name: golangci-lint - image: golangci/golangci-lint:v1.55 + image: golangci/golangci-lint:v1.57 commands: - golangci-lint run diff --git a/bench_test.go b/bench_test.go index 0ee96c1..df0fad5 100644 --- a/bench_test.go +++ b/bench_test.go @@ -166,7 +166,9 @@ func BenchmarkDisabledAccumulatedContext(b *testing.B) { b.Run("4devs/log.Context", func(b *testing.B) { b.ResetTimer() + logger := NewLogger().With(log.GoVersion("goversion")) + b.RunParallel(func(pb *testing.PB) { for pb.Next() { logger.InfoKV(ctx, getMessage(0), fakeFields()...) diff --git a/example/log.go b/example/log.go index 9325882..a8ebfc8 100644 --- a/example/log.go +++ b/example/log.go @@ -21,7 +21,7 @@ func main() { logger.AlertKV(ctx, "alert message new logger", field.String("string", "value")) service(ctx, logger) - strLogger := log.New(log.WithFormat(log.FormatWithBracket())).With(log.WithSource(10, log.TrimPath), log.WithTime(log.KeyTime, time.RFC3339)) + strLogger := log.New(log.WithFormat(log.FormatWithBracket(field.NewEncoderText()))).With(log.WithSource(10, log.TrimPath), log.WithTime(log.KeyTime, time.RFC3339)) strLogger.AlertKV(ctx, "alert message new txt logger", field.String("string", "value")) service(ctx, strLogger) } diff --git a/field/encoder.go b/field/encoder.go index 86497c1..f2fc9cb 100644 --- a/field/encoder.go +++ b/field/encoder.go @@ -174,6 +174,7 @@ func needsQuoting(in string) bool { if char != '\\' && (char == ' ' || char == '=' || !safeSet[char]) { return true } + i++ continue diff --git a/middleware.go b/middleware.go index 27936c6..bd16860 100644 --- a/middleware.go +++ b/middleware.go @@ -38,6 +38,7 @@ func With(logger Logger, mw ...Middleware) Logger { if curI == lastI { return logger(currentCtx, currentEntry) } + curI++ n, err := mw[curI](currentCtx, currentEntry, chainHandler) curI-- -- 2.30.2 From 4baf4b36e7f034e0b335836e63fd8beed67c831c Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 4 Apr 2024 12:17:02 +0300 Subject: [PATCH 2/2] set golang version --- .drone.yml | 2 +- logger_example_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index b873675..adc1199 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: logger steps: - name: test - image: golang:1.22 + image: golang:1.22.2 volumes: - name: deps path: /go/src/mod diff --git a/logger_example_test.go b/logger_example_test.go index 3150b66..ffda553 100644 --- a/logger_example_test.go +++ b/logger_example_test.go @@ -213,8 +213,8 @@ func ExampleNew_jsonFormat() { logger.Err(ctx, "same error message") logger.WarnKVs(ctx, "same warn message", "obj", Obj{Name: "obj name"}) // Output: - // {"msg":"same error message","level":"error","go-version":"go1.21.5"} - // {"msg":"same warn message","obj":{"Name":"obj name","IsEnable":false},"level":"warning","go-version":"go1.21.5"} + // {"msg":"same error message","level":"error","go-version":"go1.22.2"} + // {"msg":"same warn message","obj":{"Name":"obj name","IsEnable":false},"level":"warning","go-version":"go1.22.2"} } func ExampleNew_textEncoding() { @@ -227,8 +227,8 @@ func ExampleNew_textEncoding() { logger.InfoKVs(ctx, "same info message", "api-version", 0.1, "obj", Obj{Name: "text value", IsEnable: true}) // Output: - // msg="same error message" level=error go-version=go1.21.5 - // msg="same info message" api-version=0.1 obj={Name:text value IsEnable:true} level=info go-version=go1.21.5 + // msg="same error message" level=error go-version=go1.22.2 + // msg="same info message" api-version=0.1 obj={Name:text value IsEnable:true} level=info go-version=go1.22.2 } type ctxKey string @@ -252,7 +252,7 @@ func ExampleWith() { log.GoVersion("go"), ) logger.Info(vctx, "same message") - // Output: msg="same message" level=info requestID=6a5fa048-7181-11ea-bc55-0242ac130003 api=0.1.0 go=go1.21.5 + // Output: msg="same message" level=info requestID=6a5fa048-7181-11ea-bc55-0242ac130003 api=0.1.0 go=go1.22.2 } func ExampleLogger_Print() { @@ -263,7 +263,7 @@ func ExampleLogger_Print() { log.GoVersion("go"), ) logger.Print("same message") - // Output: msg="same message" level=info client=http api=0.1.0 go=go1.21.5 + // Output: msg="same message" level=info client=http api=0.1.0 go=go1.22.2 } func ExamplePrint() { -- 2.30.2