Class: Logster::GroupingPattern

Inherits:
Pattern
  • Object
show all
Defined in:
lib/logster/grouping_pattern.rb

Constant Summary collapse

CACHE_KEY =
:grouping

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pattern

child_classes, find, find_all, inherited, #initialize, #modify, parse_pattern, #pattern, #to_s, valid?, #valid?

Constructor Details

This class inherits a constructor from Logster::Pattern

Class Method Details

.set_nameObject



6
7
8
# File 'lib/logster/grouping_pattern.rb', line 6

def self.set_name
  "__LOGSTER__grouping_patterns_set".freeze
end

Instance Method Details

#destroy(clear_cache: true) ⇒ Object

arg used in tests



24
25
26
27
28
# File 'lib/logster/grouping_pattern.rb', line 24

def destroy(clear_cache: true) # arg used in tests
  super()
  @store.remove_pattern_group(self.pattern)
  @store.clear_patterns_cache(CACHE_KEY) if clear_cache
end

#save(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/logster/grouping_pattern.rb', line 10

def save(args = {})
  super
  existing_groups = @store.find_pattern_groups
  group = Logster::Group.new(self.to_s)
  messages = @store.get_all_messages(with_env: false)
  messages.select! do |m|
    m.message =~ self.pattern && existing_groups.none? { |g| g.messages_keys.include?(m.key) }
  end
  group.messages = messages
  group.count = messages.size
  @store.save_pattern_group(group) if group.changed?
  @store.clear_patterns_cache(CACHE_KEY)
end