mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-20 07:21:27 +02:00
client: remove gRPC logger implementation and related interceptor references
This commit is contained in:
@@ -21,8 +21,6 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
grpcLogger "github.com/netbirdio/netbird/client/grpc/logger"
|
||||
|
||||
"github.com/netbirdio/netbird/client/internal"
|
||||
)
|
||||
|
||||
@@ -243,7 +241,6 @@ func DialClientGRPCServer(ctx context.Context, addr string) (*grpc.ClientConn, e
|
||||
strings.TrimPrefix(addr, "tcp://"),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithUnaryInterceptor(grpcLogger.UnaryClientInterceptor()),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// UnaryClientInterceptor logs gRPC requests using the global logrus logger
|
||||
func UnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
||||
return func(
|
||||
ctx context.Context,
|
||||
method string,
|
||||
req, reply interface{},
|
||||
cc *grpc.ClientConn,
|
||||
invoker grpc.UnaryInvoker,
|
||||
opts ...grpc.CallOption,
|
||||
) error {
|
||||
start := time.Now()
|
||||
|
||||
// don't log if log output is not a file
|
||||
ignoreLog := log.StandardLogger().Out == os.Stdout || log.StandardLogger().Out == os.Stderr
|
||||
|
||||
if !ignoreLog {
|
||||
// log the request
|
||||
if msg, ok := req.(proto.Message); ok {
|
||||
if jsonReq, err := protojson.Marshal(msg); err == nil {
|
||||
log.Debugf("gRPC request initiated: method=%s, request=%s", method, jsonReq)
|
||||
} else {
|
||||
log.Warnf("Could not marshal gRPC request: method=%s, error=%v", method, err)
|
||||
}
|
||||
} else {
|
||||
log.Debugf("gRPC request initiated: method=%s, requestType=%T", method, req)
|
||||
}
|
||||
}
|
||||
|
||||
err := invoker(ctx, method, req, reply, cc, opts...)
|
||||
|
||||
duration := time.Since(start)
|
||||
|
||||
// log the response
|
||||
if !ignoreLog {
|
||||
if err != nil {
|
||||
log.Errorf("gRPC request failed: method=%s, duration=%v, error=%v", method, duration, err)
|
||||
} else {
|
||||
if msg, ok := reply.(proto.Message); ok {
|
||||
if jsonReply, err := protojson.Marshal(msg); err == nil {
|
||||
log.Debugf("gRPC request succeeded: method=%s, duration=%v, response=%s", method, duration, jsonReply)
|
||||
} else {
|
||||
log.Warnf("Could not marshal gRPC response: method=%s, error=%v", method, err)
|
||||
}
|
||||
} else {
|
||||
log.Debugf("gRPC request succeeded: method=%s, duration=%v, responseType=%T", method, duration, reply)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,6 @@ import (
|
||||
"github.com/netbirdio/netbird/client/ui/process"
|
||||
"github.com/netbirdio/netbird/util"
|
||||
|
||||
grpcLogger "github.com/netbirdio/netbird/client/grpc/logger"
|
||||
|
||||
"github.com/netbirdio/netbird/version"
|
||||
)
|
||||
|
||||
@@ -824,7 +822,6 @@ func (s *serviceClient) getSrvClient(timeout time.Duration) (proto.DaemonService
|
||||
strings.TrimPrefix(s.addr, "tcp://"),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithUnaryInterceptor(grpcLogger.UnaryClientInterceptor()),
|
||||
grpc.WithUserAgent(desktop.GetUIUserAgent()),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
|
||||
grpcLogger "github.com/netbirdio/netbird/client/grpc/logger"
|
||||
"github.com/netbirdio/netbird/util/embeddedroots"
|
||||
nbnet "github.com/netbirdio/netbird/util/net"
|
||||
)
|
||||
@@ -85,7 +84,6 @@ func CreateConnection(addr string, tlsEnabled bool) (*grpc.ClientConn, error) {
|
||||
Time: 30 * time.Second,
|
||||
Timeout: 10 * time.Second,
|
||||
}),
|
||||
grpc.WithUnaryInterceptor(grpcLogger.UnaryClientInterceptor()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("DialContext error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user