Module: Deimos::Logging

Defined in:
lib/deimos/logging.rb

Class Method Summary collapse

Class Method Details

._payloads(messages) ⇒ Object



32
33
34
# File 'lib/deimos/logging.rb', line 32

def _payloads(messages)

end

.log_add(method, msg) ⇒ Object



5
6
7
8
9
10
# File 'lib/deimos/logging.rb', line 5

def log_add(method, msg)
  Karafka.logger.tagged('Deimos') do |logger|
    logger.send(method, msg.to_json)
  end

end

.log_debug(*args) ⇒ Object



16
17
18
# File 'lib/deimos/logging.rb', line 16

def log_debug(*args)
  log_add(:debug, *args)
end

.log_error(*args) ⇒ Object



20
21
22
# File 'lib/deimos/logging.rb', line 20

def log_error(*args)
  log_add(:error, *args)
end

.log_info(*args) ⇒ Object



12
13
14
# File 'lib/deimos/logging.rb', line 12

def log_info(*args)
  log_add(:info, *args)
end

.log_warn(*args) ⇒ Object



24
25
26
# File 'lib/deimos/logging.rb', line 24

def log_warn(*args)
  log_add(:warn, *args)
end

.messages_log_text(payload_log, messages) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/deimos/logging.rb', line 36

def messages_log_text(payload_log, messages)
  log_message = {}

  case payload_log
  when :keys
    keys = messages.map do |m|
      m.respond_to?(:payload) ? m.key || m.payload['message_id'] : m[:key] || m[:payload_key] || m[:payload]['message_id']
    end
    log_message.merge!(
      payload_keys: keys
    )
  when :count
    log_message.merge!(
      payloads_count: messages.count
    )
  when :headers
    log_message.merge!(
      payload_headers: messages.map { |m| m.respond_to?(:headers) ? m.headers : m[:headers] }
    )
  else
    log_message.merge!(
      payloads: messages.map do |m|
        {
          payload: m.respond_to?(:payload) ? m.payload : m[:payload],
          key: m.respond_to?(:payload) ? m.key : m[:key]
        }
      end
    )
  end

  log_message
end

.metadata_log_text(metadata) ⇒ Object



28
29
30
# File 'lib/deimos/logging.rb', line 28

def ()
  .to_h.slice(:timestamp, :offset, :first_offset, :last_offset, :partition, :topic, :size)
end