Class: Hanami::Events::CloudPubsub::Middleware::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/events/cloud_pubsub/middleware/logging.rb

Overview

Middleware used for logging useful information about an event

Instance Method Summary collapse

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.message_id}) took #{seconds} seconds to process
  MSG
end