Class: Hanami::Events::CloudPubsub::Middleware::Logging
- Inherits:
-
Object
- Object
- Hanami::Events::CloudPubsub::Middleware::Logging
- Defined in:
- lib/hanami/events/cloud_pubsub/middleware/logging.rb
Overview
Middleware used for logging useful information about an event
Instance Method Summary collapse
- #call(msg, **opts) ⇒ Object
-
#initialize(logger: nil) ⇒ Logging
constructor
A new instance of Logging.
Constructor Details
#initialize(logger: nil) ⇒ Logging
Returns a new instance of Logging.
9 10 11 |
# File 'lib/hanami/events/cloud_pubsub/middleware/logging.rb', line 9 def initialize(logger: nil) @logger = logger end |
Instance Method Details
#call(msg, **opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hanami/events/cloud_pubsub/middleware/logging.rb', line 13 def call(msg, **opts) started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) yield(**opts) ensure ended_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) seconds = ended_at - started_at logger.info <<~MSG Processed message(id: #{msg.}) took #{seconds} seconds to process MSG end |