From 7a0efa3b6de0890cbe9a8d302da23d5d55aa718b Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 3 Nov 2022 16:53:58 +0300 Subject: [PATCH] Migrating to unified logger interface --- .gitignore | 1 + go.mod | 2 +- go.sum | 6 ++++++ trc.go | 8 +++----- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e92f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags diff --git a/go.mod b/go.mod index 82ca48b..d134b72 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 3dfe1c9..a553532 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/trc.go b/trc.go index b878720..801f392 100644 --- a/trc.go +++ b/trc.go @@ -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) }