Class: Eco::API::Common::Session::Logger::Cache
- 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
- #add(level, datetime, message, formatted) ⇒ Object
- #cache ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #level(level) ⇒ Object
- #logs(level: nil, start_time: nil, end_time: nil) ⇒ Object
- #reset(level: nil, start_time: nil, end_time: nil) ⇒ Object
Constructor Details
#initialize ⇒ Cache
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, , formatted) Logger::Log.new(level, datetime, , formatted).tap do |log| self.level(level).push(log) end end |
#cache ⇒ Object
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 |