Class: SmartProxies::LogBuffer

Inherits:
Object
  • Object
show all
Defined in:
app/services/smart_proxies/log_buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ LogBuffer

Returns a new instance of LogBuffer.


2
3
4
# File 'app/services/smart_proxies/log_buffer.rb', line 2

def initialize(hash)
  @logs = hash
end

Instance Method Details

#aggregated_logsObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/smart_proxies/log_buffer.rb', line 10

def aggregated_logs
  @aggregated ||= begin
    aggregated = { 'debug' => 0, 'info' => 0, 'warn' => 0, 'error' => 0, 'fatal' => 0 }
    log_entries.each do |log|
      level = log['level'].try(:downcase)
      if aggregated[level]
        aggregated[level] += 1
      else
        aggregated[level] = 1
      end
    end
    aggregated
  end
end

#debug_messagesObject


33
34
35
# File 'app/services/smart_proxies/log_buffer.rb', line 33

def debug_messages
  aggregated_logs['debug'] || 0
end

#error_messagesObject


53
54
55
# File 'app/services/smart_proxies/log_buffer.rb', line 53

def error_messages
  aggregated_logs['error'] || 0
end

#error_or_fatal_messagesObject


57
58
59
# File 'app/services/smart_proxies/log_buffer.rb', line 57

def error_or_fatal_messages
  (fatal_messages + error_messages) || 0
end

#failed_module_namesObject


29
30
31
# File 'app/services/smart_proxies/log_buffer.rb', line 29

def failed_module_names
  failed_modules.keys || []
end

#failed_modulesObject


25
26
27
# File 'app/services/smart_proxies/log_buffer.rb', line 25

def failed_modules
  @logs['info'].try(:fetch, 'failed_modules') || {}
end

#fatal_messagesObject


49
50
51
# File 'app/services/smart_proxies/log_buffer.rb', line 49

def fatal_messages
  aggregated_logs['fatal'] || 0
end

#info_messagesObject


37
38
39
# File 'app/services/smart_proxies/log_buffer.rb', line 37

def info_messages
  aggregated_logs['info'] || 0
end

#info_or_debug_messagesObject


41
42
43
# File 'app/services/smart_proxies/log_buffer.rb', line 41

def info_or_debug_messages
  (info_messages + debug_messages) || 0
end

#log_entriesObject


6
7
8
# File 'app/services/smart_proxies/log_buffer.rb', line 6

def log_entries
  @logs['logs'] || []
end

#warn_messagesObject


45
46
47
# File 'app/services/smart_proxies/log_buffer.rb', line 45

def warn_messages
  aggregated_logs['warn'] || 0
end