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 =
["UNKNOWN", "FATAL", "ERROR", "WARN", "INFO", "DEBUG"]

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



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

def initialize
  reset
end

Instance Method Details

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



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

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

#cacheObject



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

def cache
  @cache ||= {}
end

#level(level) ⇒ Object



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

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

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



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

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



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

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