Module: Julewire::SemanticLogger::AppenderHealth

Defined in:
lib/julewire/semantic_logger/appender_health.rb

Class Method Summary collapse

Class Method Details

.appender_type(value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/julewire/semantic_logger/appender_health.rb', line 18

def appender_type(value)
  case value
  when ::SemanticLogger::Appender::Async
    "async"
  when ::SemanticLogger::Appenders
    "multi_appender"
  when ::SemanticLogger::Appender::File
    "file"
  when ::SemanticLogger::Appender::IO
    "io"
  else
    "appender"
  end
end

.async_health(value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/julewire/semantic_logger/appender_health.rb', line 33

def async_health(value)
  return {} unless value.is_a?(::SemanticLogger::Appender::Async)

  {
    active: value.active?,
    capped: value.capped?,
    max_queue_size: value.max_queue_size,
    queue_size: value.queue.size,
    wrapped: call(value.appender)
  }
end

.call(value, index: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/julewire/semantic_logger/appender_health.rb', line 7

def call(value, index: nil)
  {
    appender_class: value.class.name,
    index: index,
    type: appender_type(value)
  }.compact
    .merge(async_health(value))
    .merge(file_health(value))
    .merge(collection_health(value))
end

.collection_health(value) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/julewire/semantic_logger/appender_health.rb', line 57

def collection_health(value)
  return {} unless value.is_a?(::SemanticLogger::Appenders)

  {
    appender_count: value.length,
    appenders: value.each_with_index.map { |child, index| call(child, index: index) }
  }
end

.file_health(value) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/julewire/semantic_logger/appender_health.rb', line 45

def file_health(value)
  return {} unless value.is_a?(::SemanticLogger::Appender::File)

  {
    current_file_name: value.current_file_name,
    file_name: value.file_name,
    log_count: value.log_count,
    log_size: value.log_size,
    reopen_at: value.reopen_at&.utc&.iso8601
  }
end