Class: AiClient::LoggingMiddleware
- Inherits:
-
Object
- Object
- AiClient::LoggingMiddleware
- Defined in:
- lib/ai_client/logger_middleware.rb
Overview
Instance Method Summary collapse
-
#call(client, next_middleware, *args) ⇒ Object
Calls the next middleware in the stack while logging the start and finish times.
-
#initialize(logger) ⇒ LoggingMiddleware
constructor
Initializes the LoggingMiddleware with a logger.
Constructor Details
#initialize(logger) ⇒ LoggingMiddleware
Initializes the LoggingMiddleware with a logger.
24 25 26 |
# File 'lib/ai_client/logger_middleware.rb', line 24 def initialize(logger) @logger = logger end |
Instance Method Details
#call(client, next_middleware, *args) ⇒ Object
Calls the next middleware in the stack while logging the start and finish times.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ai_client/logger_middleware.rb', line 36 def call(client, next_middleware, *args) method_name = args.first.is_a?(Symbol) ? args.first : 'unknown method' @logger.info("Starting #{method_name} call") start_time = Time.now result = next_middleware.call(*args) end_time = Time.now duration = end_time - start_time @logger.info("Finished #{method_name} call (took #{duration.round(3)} seconds)") result end |