MCPcopy Index your code
hub / github.com/PasarGuard/node / logRequest

Function logRequest

controller/rpc/middleware.go:119–135  ·  view source on GitHub ↗
(ctx context.Context, method string, err error)

Source from the content-addressed store, hash-verified

117}
118
119func logRequest(ctx context.Context, method string, err error) {
120 // Extract client IP
121 clientIP := "unknown"
122 if p, ok := peer.FromContext(ctx); ok {
123 clientIP = p.Addr.String()
124 }
125
126 logEntry := fmt.Sprintf("IP: %s, Method: %s,", clientIP, strings.TrimPrefix(method, "/service.NodeService/"))
127
128 // Log based on the response status
129 if err != nil {
130 st, _ := status.FromError(err)
131 log.Println(logEntry, "Code:", st.Code())
132 } else {
133 log.Println(logEntry, "Status: Success")
134 }
135}
136
137func LoggingInterceptor(s *Service) grpc.UnaryServerInterceptor {
138 return func(

Callers 2

LoggingInterceptorFunction · 0.85
LoggingStreamInterceptorFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected