Class: Upfluence::Utils::Thrift::Middleware::RequestLogger
- Inherits:
-
Object
- Object
- Upfluence::Utils::Thrift::Middleware::RequestLogger
- Defined in:
- lib/upfluence/utils/thrift/middleware/request_logger.rb
Instance Method Summary collapse
-
#initialize(app, logger) ⇒ RequestLogger
constructor
A new instance of RequestLogger.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(app, logger) ⇒ RequestLogger
Returns a new instance of RequestLogger.
6 7 8 9 |
# File 'lib/upfluence/utils/thrift/middleware/request_logger.rb', line 6 def initialize(app, logger) @app = app @logger = logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/upfluence/utils/thrift/middleware/request_logger.rb', line 11 def method_missing(method, *args, &block) args_str = args.map(&:to_s).join(',')[0..99] t0 = Time.now @logger.info( "Running method `#{method}` with args [#{args_str}]" ) result = @app.send method, *args, &block @logger.info( "Finished method `#{method}` with args [#{args_str}]. Took: #{time_since(t0)}ms" ) result rescue => e @logger.error( "Finished method `#{method}` with args [#{args_str}] failed: #{e.class}. Took: #{time_since(t0)}ms" ) raise e end |