Class: RailsGrpc::Interceptor::LoggingInterceptor
- Inherits:
- 
      GRPC::ServerInterceptor
      
        - Object
- GRPC::ServerInterceptor
- RailsGrpc::Interceptor::LoggingInterceptor
 
- Defined in:
- lib/rails_grpc/interceptor/logging_interceptor.rb
Instance Method Summary collapse
- 
  
    
      #initialize(logger)  ⇒ LoggingInterceptor 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of LoggingInterceptor. 
- #request_response(request: nil, call: nil, method: nil) ⇒ Object
Constructor Details
#initialize(logger) ⇒ LoggingInterceptor
| 6 7 8 | # File 'lib/rails_grpc/interceptor/logging_interceptor.rb', line 6 def initialize(logger) @logger = logger end | 
Instance Method Details
#request_response(request: nil, call: nil, method: nil) ⇒ Object
| 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # File 'lib/rails_grpc/interceptor/logging_interceptor.rb', line 10 def request_response(request: nil, call: nil, method: nil) grpc_method = "#{method.owner.name}##{method.name}" logger = @logger logger.info("[GRPC] #{grpc_method}") t = Time.now begin yield rescue => e logger.error(e) logger.error(e.backtrace.join("\n")) raise e end t = Time.now - t display_duration = "%.1f ms" % (t * 1000.0) logger.info("[GRPC response] (#{display_duration}) #{grpc_method}") end |