(ctx context.Context, method string, err error)
| 117 | } |
| 118 | |
| 119 | func 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 | |
| 137 | func LoggingInterceptor(s *Service) grpc.UnaryServerInterceptor { |
| 138 | return func( |
no test coverage detected