3 Commits

Author SHA1 Message Date
859a8d88f7 Merge pull request 'update ling and go version' (#17) from format into master
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Reviewed-on: #17
2024-04-04 12:19:45 +03:00
4baf4b36e7 set golang version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2024-04-04 12:17:02 +03:00
andrey
2fd0c1f9ec update ling and go version
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2024-04-04 12:12:09 +03:00
6 changed files with 13 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ name: logger
steps: steps:
- name: test - name: test
image: golang:1.21.5 image: golang:1.22.2
volumes: volumes:
- name: deps - name: deps
path: /go/src/mod path: /go/src/mod
@@ -13,7 +13,7 @@ steps:
- go test - go test
- name: golangci-lint - name: golangci-lint
image: golangci/golangci-lint:v1.55 image: golangci/golangci-lint:v1.57
commands: commands:
- golangci-lint run - golangci-lint run

View File

@@ -166,7 +166,9 @@ func BenchmarkDisabledAccumulatedContext(b *testing.B) {
b.Run("4devs/log.Context", func(b *testing.B) { b.Run("4devs/log.Context", func(b *testing.B) {
b.ResetTimer() b.ResetTimer()
logger := NewLogger().With(log.GoVersion("goversion")) logger := NewLogger().With(log.GoVersion("goversion"))
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { for pb.Next() {
logger.InfoKV(ctx, getMessage(0), fakeFields()...) logger.InfoKV(ctx, getMessage(0), fakeFields()...)

View File

@@ -21,7 +21,7 @@ func main() {
logger.AlertKV(ctx, "alert message new logger", field.String("string", "value")) logger.AlertKV(ctx, "alert message new logger", field.String("string", "value"))
service(ctx, logger) 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")) strLogger.AlertKV(ctx, "alert message new txt logger", field.String("string", "value"))
service(ctx, strLogger) service(ctx, strLogger)
} }

View File

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

View File

@@ -213,8 +213,8 @@ func ExampleNew_jsonFormat() {
logger.Err(ctx, "same error message") logger.Err(ctx, "same error message")
logger.WarnKVs(ctx, "same warn message", "obj", Obj{Name: "obj name"}) logger.WarnKVs(ctx, "same warn message", "obj", Obj{Name: "obj name"})
// Output: // Output:
// {"msg":"same error message","level":"error","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.21.5"} // {"msg":"same warn message","obj":{"Name":"obj name","IsEnable":false},"level":"warning","go-version":"go1.22.2"}
} }
func ExampleNew_textEncoding() { 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}) logger.InfoKVs(ctx, "same info message", "api-version", 0.1, "obj", Obj{Name: "text value", IsEnable: true})
// Output: // Output:
// msg="same error message" level=error 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.21.5 // msg="same info message" api-version=0.1 obj={Name:text value IsEnable:true} level=info go-version=go1.22.2
} }
type ctxKey string type ctxKey string
@@ -252,7 +252,7 @@ func ExampleWith() {
log.GoVersion("go"), log.GoVersion("go"),
) )
logger.Info(vctx, "same message") 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() { func ExampleLogger_Print() {
@@ -263,7 +263,7 @@ func ExampleLogger_Print() {
log.GoVersion("go"), log.GoVersion("go"),
) )
logger.Print("same message") 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() { func ExamplePrint() {

View File

@@ -38,6 +38,7 @@ func With(logger Logger, mw ...Middleware) Logger {
if curI == lastI { if curI == lastI {
return logger(currentCtx, currentEntry) return logger(currentCtx, currentEntry)
} }
curI++ curI++
n, err := mw[curI](currentCtx, currentEntry, chainHandler) n, err := mw[curI](currentCtx, currentEntry, chainHandler)
curI-- curI--