update ling and go version #17

Merged
andrey merged 2 commits from format into master 9 months ago
  1. 4
      .drone.yml
  2. 2
      bench_test.go
  3. 2
      example/log.go
  4. 1
      field/encoder.go
  5. 12
      logger_example_test.go
  6. 1
      middleware.go

4
.drone.yml

@ -5,7 +5,7 @@ name: logger
steps:
- name: test
image: golang:1.21.5
image: golang:1.22.2
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

2
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()...)

2
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)
}

1
field/encoder.go

@ -174,6 +174,7 @@ func needsQuoting(in string) bool {
if char != '\\' && (char == ' ' || char == '=' || !safeSet[char]) {
return true
}
i++
continue

12
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() {

1
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--

Loading…
Cancel
Save