Class: DispatchRider::Logging::LifecycleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch-rider/logging/lifecycle_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, message, options = {}) ⇒ LifecycleLogger

Returns a new instance of LifecycleLogger.



44
45
46
47
48
# File 'lib/dispatch-rider/logging/lifecycle_logger.rb', line 44

def initialize(kind, message, options = {})
  @kind = kind
  @message = message
  @options = options
end

Class Method Details

.log_error_handler_fail(message, exception) ⇒ Object



5
6
7
# File 'lib/dispatch-rider/logging/lifecycle_logger.rb', line 5

def log_error_handler_fail(message, exception)
  new(:error_handler_fail, message, exception: exception).log
end

.log_got_stop(reason, message) ⇒ Object



9
10
11
# File 'lib/dispatch-rider/logging/lifecycle_logger.rb', line 9

def log_got_stop(reason, message)
  new(:stop, message, reason: reason).log
end

.wrap_handling(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dispatch-rider/logging/lifecycle_logger.rb', line 13

def wrap_handling(message)
  start_time = Time.now
  log_start(message)
  yield
  log_success(message)
rescue => exception
  log_fail(message, exception)
  raise exception
ensure
  log_complete(message, Time.now - start_time)
end

Instance Method Details

#logObject



50
51
52
# File 'lib/dispatch-rider/logging/lifecycle_logger.rb', line 50

def log
  logger.send(log_action, formatted_data)
end