Class: Eco::API::Common::Session::Logger::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/common/session/logger/cache.rb

Constant Summary collapse

LEVELS =
%w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
CHANNELS =
Logger::CHANNELS.map(&:to_s).map(&:upcase).freeze

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



10
11
12
# File 'lib/eco/api/common/session/logger/cache.rb', line 10

def initialize
  reset
end

Instance Method Details

#add(level, datetime, message, formatted) ⇒ Object



18
19
20
21
22
# File 'lib/eco/api/common/session/logger/cache.rb', line 18

def add(level, datetime, message, formatted)
  Logger::Log.new(level, datetime, message, formatted).tap do |log|
    self.level(level).push(log)
  end
end

#cacheObject



24
25
26
# File 'lib/eco/api/common/session/logger/cache.rb', line 24

def cache
  @cache ||= {}
end

#level(level) ⇒ Object



14
15
16
# File 'lib/eco/api/common/session/logger/cache.rb', line 14

def level(level)
  cache[to_level(level)] ||= []
end

#logs(level: nil, start_time: nil, end_time: nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/eco/api/common/session/logger/cache.rb', line 37

def logs(level: nil, start_time: nil, end_time: nil)
  where(start_time, end_time) do |cond|
    to_levels(level).map do |lev|
      self.level(lev).select(&cond)
    end.flatten
  end.sort
end

#reset(level: nil, start_time: nil, end_time: nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/eco/api/common/session/logger/cache.rb', line 28

def reset(level: nil, start_time: nil, end_time: nil)
  where(start_time, end_time) do |cond|
    to_levels(level).map do |lev|
      self.level(lev).reject(&cond)
    end
  end
  self
end