diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-03-17 12:07:08 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-03-25 11:58:39 +0300 |
commit | f69deedabfe6f8ddcda9f95879193b968675dc5f (patch) | |
tree | c3060d73d330cced29e6c3f05cd02a16cf792703 /internal/praefect/grpc-proxy | |
parent | d756ece7e0505ceed1f950c86ad1bb4c28bfca75 (diff) |
grpc: Convert to use `grpclog.SetLoggerV2()`
The function `grpclog.SetLogger()` has been deprecated upstream in favor
of a new and more flexible `grpclog.SetLoggerV2()` that can
differentiate the log level. As the standard `log.Logger` interface does
not have the `Error` family of functions implemented, we cannot use it
out of the box as a logger for grpclog. We could implement these
functions ourselves on top of `log.Logger`, but that'd mean we have to
implement three functions. Instead, let's make use of the helper
function `grpclog.NewLoggerV2()`, that simply accepts an `io.Writer`.
Diffstat (limited to 'internal/praefect/grpc-proxy')
-rw-r--r-- | internal/praefect/grpc-proxy/proxy/handler_test.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/internal/praefect/grpc-proxy/proxy/handler_test.go b/internal/praefect/grpc-proxy/proxy/handler_test.go index a4ca14a12..55e5a800d 100644 --- a/internal/praefect/grpc-proxy/proxy/handler_test.go +++ b/internal/praefect/grpc-proxy/proxy/handler_test.go @@ -1,10 +1,6 @@ // Copyright 2017 Michal Witkowski. All Rights Reserved. // See LICENSE for licensing terms. -// TODO: remove the following linter override when the deprecations are fixed -// in issue https://gitlab.com/gitlab-org/gitaly/issues/1663 -//lint:file-ignore SA1019 Ignore all gRPC deprecations until issue #1663 - package proxy_test import ( @@ -52,8 +48,22 @@ const ( countListResponses = 20 ) +type testLogger struct { + *log.Logger +} + +func (l *testLogger) Write(p []byte) (int, error) { + if err := l.Output(1, string(p)); err != nil { + return 0, err + } + return -1, nil +} + func TestMain(m *testing.M) { - grpclog.SetLogger(log.New(os.Stderr, "grpc: ", log.LstdFlags)) + logger := &testLogger{ + log.New(os.Stderr, "grpc: ", log.LstdFlags), + } + grpclog.SetLoggerV2(grpclog.NewLoggerV2(logger, nil, nil)) m.Run() os.Exit(0) } |