Class: Logster::BaseStore

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

Direct Known Subclasses

RedisStore

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseStore

Returns a new instance of BaseStore.



6
7
8
9
10
11
# File 'lib/logster/base_store.rb', line 6

def initialize
  @max_retention = 60 * 60 * 24 * 7
  @skip_empty = true
  @allow_custom_patterns = false
  @patterns_cache = Logster::Cache.new
end

Instance Attribute Details

#allow_custom_patternsObject

Returns the value of attribute allow_custom_patterns.



4
5
6
# File 'lib/logster/base_store.rb', line 4

def allow_custom_patterns
  @allow_custom_patterns
end

#ignoreObject

Returns the value of attribute ignore.



4
5
6
# File 'lib/logster/base_store.rb', line 4

def ignore
  @ignore
end

#levelObject

Returns the value of attribute level.



4
5
6
# File 'lib/logster/base_store.rb', line 4

def level
  @level
end

#max_retentionObject

Returns the value of attribute max_retention.



4
5
6
# File 'lib/logster/base_store.rb', line 4

def max_retention
  @max_retention
end

#skip_emptyObject

Returns the value of attribute skip_empty.



4
5
6
# File 'lib/logster/base_store.rb', line 4

def skip_empty
  @skip_empty
end

Instance Method Details

#bulk_get(message_keys) ⇒ Object

Get a group of messages by their message_keys



50
51
52
# File 'lib/logster/base_store.rb', line 50

def bulk_get(message_keys)
  not_implemented
end

#check_rate_limits(severity) ⇒ Object

Checks all the existing rate limiters to check if any has been exceeded



85
86
87
# File 'lib/logster/base_store.rb', line 85

def check_rate_limits(severity)
  not_implemented
end

#clearObject

Delete all unprotected messages in the store.



35
36
37
# File 'lib/logster/base_store.rb', line 35

def clear
  not_implemented
end

#clear_allObject

Delete all messages, including protected messages.



40
41
42
# File 'lib/logster/base_store.rb', line 40

def clear_all
  not_implemented
end

#clear_suppression_patterns_cacheObject



159
160
161
# File 'lib/logster/base_store.rb', line 159

def clear_suppression_patterns_cache
  @patterns_cache.clear
end

#countObject

The number of messages currently stored.



30
31
32
# File 'lib/logster/base_store.rb', line 30

def count
  not_implemented
end

#delete(message_key) ⇒ Object



64
65
66
# File 'lib/logster/base_store.rb', line 64

def delete(message_key)
  not_implemented
end

#get(message_key, load_env: true) ⇒ Object

Get a message by its message_key



45
46
47
# File 'lib/logster/base_store.rb', line 45

def get(message_key, load_env: true)
  not_implemented
end

#get_env(message_key) ⇒ Object

Get a message’s env by its message_key



55
56
57
# File 'lib/logster/base_store.rb', line 55

def get_env(message_key)
  not_implemented
end

#get_patterns(set_name) ⇒ Object

returns an array of strings each of which must be convertible to regexp



100
101
102
# File 'lib/logster/base_store.rb', line 100

def get_patterns(set_name)
  not_implemented
end

#insert_pattern(set_name, pattern) ⇒ Object

takes a string as ‘pattern` and places it under the set `set_name`



90
91
92
# File 'lib/logster/base_store.rb', line 90

def insert_pattern(set_name, pattern)
  not_implemented
end

#protect(message_key) ⇒ Object

Mark a message as protected; i.e. it is not deleted by the #clear method



60
61
62
# File 'lib/logster/base_store.rb', line 60

def protect(message_key)
  not_implemented
end

#register_rate_limit(severities, limit, duration, &block) ⇒ Object

Registers a rate limit on the given severities of logs



80
81
82
# File 'lib/logster/base_store.rb', line 80

def register_rate_limit(severities, limit, duration, &block)
  not_implemented
end

#remove_pattern(set_name, pattern) ⇒ Object

takes a string as ‘pattern` and removes it from the set `set_name`



95
96
97
# File 'lib/logster/base_store.rb', line 95

def remove_pattern(set_name, pattern)
  not_implemented
end

#replace_and_bump(message, save_env: true) ⇒ Object

Modify the saved message to the given one (identified by message.key) and bump it to the top of the latest list



19
20
21
# File 'lib/logster/base_store.rb', line 19

def replace_and_bump(message, save_env: true)
  not_implemented
end

#report(severity, progname, msg, opts = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/logster/base_store.rb', line 104

def report(severity, progname, msg, opts = {})
  return if (!msg || (String === msg && msg.empty?)) && skip_empty
  return if level && severity < level

  message = Logster::Message.new(severity, progname, msg, opts[:timestamp], count: opts[:count])

  env = opts[:env] || {}
  backtrace = opts[:backtrace]
  if Hash === env && env[:backtrace]
    # Special - passing backtrace through env
    backtrace = env.delete(:backtrace)
  end

  message.populate_from_env(env)

  if backtrace
    if backtrace.respond_to? :join
      backtrace = backtrace.join("\n")
    end
    message.backtrace = backtrace
  else
    message.backtrace = caller.join("\n")
  end

  return if ignore && ignore.any? { |pattern| message =~ pattern }

  if Logster.config.enable_custom_patterns_via_ui || allow_custom_patterns
    custom_ignore = @patterns_cache.fetch do
      Logster::SuppressionPattern.find_all(store: self)
    end
    return if custom_ignore.any? { |pattern| message =~ pattern }
  end

  similar = nil

  if Logster.config.allow_grouping
    key = self.similar_key(message)
    similar = get(key, load_env: false) if key
  end

  if similar
    has_env = !similar.env.nil? && !similar.env.empty?
    if similar.count < Logster::MAX_GROUPING_LENGTH && !has_env
      similar.env = get_env(similar.key) || {}
    end
    save_env = similar.merge_similar_message(message)

    replace_and_bump(similar, save_env: save_env || has_env)
    similar
  else
    save message
    message
  end
end

#save(message) ⇒ Object

Save a new message at the front of the latest list.



14
15
16
# File 'lib/logster/base_store.rb', line 14

def save(message)
  not_implemented
end

#similar_key(message) ⇒ Object

Check if another message with the same grouping_key is already stored. Returns the similar message’s message.key



25
26
27
# File 'lib/logster/base_store.rb', line 25

def similar_key(message)
  not_implemented
end

#solve(message_key) ⇒ Object

Solve a particular message, causing all old messages with matching version and backtrace to be deleted (report should delete any solved messages when called)



75
76
77
# File 'lib/logster/base_store.rb', line 75

def solve(message_key)
  not_implemented
end

#unprotect(message_key) ⇒ Object

Clear the protected mark for a message.



69
70
71
# File 'lib/logster/base_store.rb', line 69

def unprotect(message_key)
  not_implemented
end