MCPcopy Create free account
hub / github.com/diillson/chatcli / loggingStreamInterceptor

Function loggingStreamInterceptor

server/middleware.go:50–71  ·  view source on GitHub ↗

loggingStreamInterceptor logs stream RPC calls.

(logger *zap.Logger)

Source from the content-addressed store, hash-verified

48
49// loggingStreamInterceptor logs stream RPC calls.
50func loggingStreamInterceptor(logger *zap.Logger) grpc.StreamServerInterceptor {
51 return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
52 start := time.Now()
53 err := handler(srv, ss)
54 duration := time.Since(start)
55
56 if err != nil {
57 logger.Warn(i18n.T("server.middleware.stream_call"),
58 zap.String("method", info.FullMethod),
59 zap.Duration("duration", duration),
60 zap.Error(err),
61 )
62 } else {
63 logger.Info(i18n.T("server.middleware.stream_call"),
64 zap.String("method", info.FullMethod),
65 zap.Duration("duration", duration),
66 )
67 }
68
69 return err
70 }
71}
72
73// isDebugMode returns true when detailed error info should be logged.
74func isDebugMode() bool {

Callers 1

NewFunction · 0.85

Calls 5

TFunction · 0.92
WarnMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected