Migrating to unified logger interface

This commit is contained in:
Pavel Shevaev 2022-11-03 16:53:58 +03:00
parent 9cbbebe7d6
commit 7a0efa3b6d
4 changed files with 11 additions and 6 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tags

2
go.mod
View File

@ -3,7 +3,7 @@ module git.bit5.ru/backend/trc
go 1.13
require (
git.bit5.ru/backend/colog v1.0.0
github.com/go-logr/logr v1.2.3
git.bit5.ru/backend/errors v1.0.0
github.com/google/uuid v1.3.0
)

6
go.sum
View File

@ -1,2 +1,8 @@
git.bit5.ru/backend/colog v1.0.0 h1:FLykTQuRfnhWYQ+dZhoaOfkxjHNEfWp4AwP/KD+ob+M=
git.bit5.ru/backend/colog v1.0.0/go.mod h1:fiOrMQ7SPBD5Pn/Tb7rG1phsDQbZaA7S0vtdnlM6BK4=
git.bit5.ru/backend/errors v1.0.0 h1:WWJ0sly44q1HQjN01X75ZAGKZwwY5Ml+XVDXMjCkToA=
git.bit5.ru/backend/errors v1.0.0/go.mod h1:75faRwsnpM0Se00/Bh7fysWQXV8oMjNJFQ6f7+r9k3Y=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

8
trc.go
View File

@ -1,12 +1,11 @@
package trc
import (
"fmt"
"net/http"
"git.bit5.ru/backend/colog"
"git.bit5.ru/backend/errors"
"github.com/google/uuid"
"github.com/go-logr/logr"
)
type TraceId string
@ -36,7 +35,6 @@ func RequestTraceId(req *http.Request) (TraceId, error) {
//-----------------------------------------------------------------------------
func NewTraceLogger(logger *colog.CoLog, traceId TraceId) *colog.CoLog {
prefix := fmt.Sprintf("[trace_id:%s]", traceId)
return logger.Clone().AddPrefix(prefix)
func NewTraceLogger(logger logr.Logger, traceId TraceId) logr.Logger {
return logger.WithValues("trace_id", traceId)
}