Module: CmAppLogger

Defined in:
lib/cm_app_logger.rb

Overview

lib/cm_app_logger.rb

Class Method Summary collapse

Class Method Details

.error(label:, data: nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/cm_app_logger.rb', line 19

def self.error(label:, data: nil)
  message = {
    label: label,
    data: data
  }

  Rails.logger.error(message.to_json)
end

.log(label:, data: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cm_app_logger.rb', line 3

def self.log(label:, data: nil)
  message = { label: label, data: data }
  start_time = Time.current
  Rails.logger.info(message.to_json)

  return unless block_given?

  # Capture the block’s return value and return it to preserve existing behavior for callers expecting that value.
  block_result = yield

  message[:start_time] = start_time
  message[:duration_ms] = (Time.current - start_time) * 1000
  Rails.logger.info(message.to_json)
  block_result
end