Class: Logster::BaseStore
- Inherits:
-
Object
- Object
- Logster::BaseStore
- Defined in:
- lib/logster/base_store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allow_custom_patterns ⇒ Object
Returns the value of attribute allow_custom_patterns.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#level ⇒ Object
Returns the value of attribute level.
-
#max_retention ⇒ Object
Returns the value of attribute max_retention.
-
#skip_empty ⇒ Object
Returns the value of attribute skip_empty.
Instance Method Summary collapse
-
#bulk_delete(message_keys, grouping_keys) ⇒ Object
Delete messages associated with given message_keys.
-
#bulk_get(message_keys) ⇒ Object
Get a group of messages by their message_keys.
-
#check_rate_limits(severity) ⇒ Object
Checks all the existing rate limiters to check if any has been exceeded.
-
#clear ⇒ Object
Delete all unprotected messages in the store.
-
#clear_all ⇒ Object
Delete all messages, including protected messages.
- #clear_patterns_cache(key) ⇒ Object
-
#count ⇒ Object
The number of messages currently stored.
- #delete(message_key) ⇒ Object
-
#find_pattern_groups(load_messages: true) ⇒ Object
find all pattern groups; returns an array of Logster::Group.
-
#get(message_key, load_env: true) ⇒ Object
Get a message by its message_key.
-
#get_all_ignore_count ⇒ Object
returns a hash that maps patterns to the number of messages they have suppressed.
-
#get_all_messages ⇒ Object
Get all messages that you have in the store.
-
#get_env(message_key) ⇒ Object
Get a message’s env by its message_key.
-
#get_patterns(set_name) ⇒ Object
returns an array of strings each of which must be convertible to regexp.
-
#increment_ignore_count(pattern) ⇒ Object
increments the number of messages that have been suppressed by a pattern.
-
#initialize ⇒ BaseStore
constructor
A new instance of BaseStore.
-
#insert_pattern(set_name, pattern) ⇒ Object
takes a string as ‘pattern` and places it under the set `set_name`.
-
#protect(message_key) ⇒ Object
Mark a message as protected; i.e.
- #rate_limited?(ip_address, perform: false, limit: 60) ⇒ Boolean
-
#register_rate_limit(severities, limit, duration, &block) ⇒ Object
Registers a rate limit on the given severities of logs.
-
#remove_ignore_count(pattern) ⇒ Object
removes number of suppressed messages by a pattern.
-
#remove_pattern(set_name, pattern) ⇒ Object
takes a string as ‘pattern` and removes it from the set `set_name`.
-
#remove_pattern_group(pattern) ⇒ Object
removes the Logster::Group instance associated with the given pattern.
-
#replace_and_bump(message) ⇒ Object
Modify the saved message to the given one (identified by message.key) and bump it to the top of the latest list.
- #report(severity, progname, msg, opts = {}) ⇒ Object
-
#save(message) ⇒ Object
Save a new message at the front of the latest list.
-
#save_pattern_group(group) ⇒ Object
saves an instance of Logster::Group.
-
#similar_key(message) ⇒ Object
Check if another message with the same grouping_key is already stored.
-
#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).
-
#unprotect(message_key) ⇒ Object
Clear the protected mark for a message.
Constructor Details
#initialize ⇒ BaseStore
Returns a new instance of BaseStore.
7 8 9 10 11 12 |
# File 'lib/logster/base_store.rb', line 7 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_patterns ⇒ Object
Returns the value of attribute allow_custom_patterns.
5 6 7 |
# File 'lib/logster/base_store.rb', line 5 def allow_custom_patterns @allow_custom_patterns end |
#ignore ⇒ Object
Returns the value of attribute ignore.
5 6 7 |
# File 'lib/logster/base_store.rb', line 5 def ignore @ignore end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/logster/base_store.rb', line 5 def level @level end |
#max_retention ⇒ Object
Returns the value of attribute max_retention.
5 6 7 |
# File 'lib/logster/base_store.rb', line 5 def max_retention @max_retention end |
#skip_empty ⇒ Object
Returns the value of attribute skip_empty.
5 6 7 |
# File 'lib/logster/base_store.rb', line 5 def skip_empty @skip_empty end |
Instance Method Details
#bulk_delete(message_keys, grouping_keys) ⇒ Object
Delete messages associated with given message_keys
75 76 77 |
# File 'lib/logster/base_store.rb', line 75 def bulk_delete(, grouping_keys) not_implemented end |
#bulk_get(message_keys) ⇒ Object
Get a group of messages by their message_keys
51 52 53 |
# File 'lib/logster/base_store.rb', line 51 def bulk_get() not_implemented end |
#check_rate_limits(severity) ⇒ Object
Checks all the existing rate limiters to check if any has been exceeded
96 97 98 |
# File 'lib/logster/base_store.rb', line 96 def check_rate_limits(severity) not_implemented end |
#clear ⇒ Object
Delete all unprotected messages in the store.
36 37 38 |
# File 'lib/logster/base_store.rb', line 36 def clear not_implemented end |
#clear_all ⇒ Object
Delete all messages, including protected messages.
41 42 43 |
# File 'lib/logster/base_store.rb', line 41 def clear_all not_implemented end |
#clear_patterns_cache(key) ⇒ Object
248 249 250 |
# File 'lib/logster/base_store.rb', line 248 def clear_patterns_cache(key) @patterns_cache.clear(key) end |
#count ⇒ Object
The number of messages currently stored.
31 32 33 |
# File 'lib/logster/base_store.rb', line 31 def count not_implemented end |
#delete(message_key) ⇒ Object
70 71 72 |
# File 'lib/logster/base_store.rb', line 70 def delete() not_implemented end |
#find_pattern_groups(load_messages: true) ⇒ Object
find all pattern groups; returns an array of Logster::Group
136 137 138 |
# File 'lib/logster/base_store.rb', line 136 def find_pattern_groups(load_messages: true) not_implemented end |
#get(message_key, load_env: true) ⇒ Object
Get a message by its message_key
46 47 48 |
# File 'lib/logster/base_store.rb', line 46 def get(, load_env: true) not_implemented end |
#get_all_ignore_count ⇒ Object
returns a hash that maps patterns to the number of messages they have suppressed
127 128 129 |
# File 'lib/logster/base_store.rb', line 127 def get_all_ignore_count not_implemented end |
#get_all_messages ⇒ Object
Get all messages that you have in the store
56 57 58 |
# File 'lib/logster/base_store.rb', line 56 def not_implemented end |
#get_env(message_key) ⇒ Object
Get a message’s env by its message_key
61 62 63 |
# File 'lib/logster/base_store.rb', line 61 def get_env() not_implemented end |
#get_patterns(set_name) ⇒ Object
returns an array of strings each of which must be convertible to regexp
111 112 113 |
# File 'lib/logster/base_store.rb', line 111 def get_patterns(set_name) not_implemented end |
#increment_ignore_count(pattern) ⇒ Object
increments the number of messages that have been suppressed by a pattern
116 117 118 |
# File 'lib/logster/base_store.rb', line 116 def increment_ignore_count(pattern) not_implemented end |
#insert_pattern(set_name, pattern) ⇒ Object
takes a string as ‘pattern` and places it under the set `set_name`
101 102 103 |
# File 'lib/logster/base_store.rb', line 101 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
66 67 68 |
# File 'lib/logster/base_store.rb', line 66 def protect() not_implemented end |
#rate_limited?(ip_address, perform: false, limit: 60) ⇒ Boolean
131 132 133 |
# File 'lib/logster/base_store.rb', line 131 def rate_limited?(ip_address, perform: false, limit: 60) not_implemented end |
#register_rate_limit(severities, limit, duration, &block) ⇒ Object
Registers a rate limit on the given severities of logs
91 92 93 |
# File 'lib/logster/base_store.rb', line 91 def register_rate_limit(severities, limit, duration, &block) not_implemented end |
#remove_ignore_count(pattern) ⇒ Object
removes number of suppressed messages by a pattern
121 122 123 |
# File 'lib/logster/base_store.rb', line 121 def remove_ignore_count(pattern) not_implemented end |
#remove_pattern(set_name, pattern) ⇒ Object
takes a string as ‘pattern` and removes it from the set `set_name`
106 107 108 |
# File 'lib/logster/base_store.rb', line 106 def remove_pattern(set_name, pattern) not_implemented end |
#remove_pattern_group(pattern) ⇒ Object
removes the Logster::Group instance associated with the given pattern
146 147 148 |
# File 'lib/logster/base_store.rb', line 146 def remove_pattern_group(pattern) not_implemented end |
#replace_and_bump(message) ⇒ Object
Modify the saved message to the given one (identified by message.key) and bump it to the top of the latest list
20 21 22 |
# File 'lib/logster/base_store.rb', line 20 def replace_and_bump() not_implemented end |
#report(severity, progname, msg, opts = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/logster/base_store.rb', line 150 def report(severity, progname, msg, opts = {}) return if (!msg || (String === msg && msg.empty?)) && skip_empty return if level && severity < level msg = msg.inspect unless String === msg msg = (msg) = Logster::Message.new(severity, progname, msg, opts[:timestamp], count: opts[:count]) env = opts[:env]&.dup || {} backtrace = opts[:backtrace] if Hash === env && env[:backtrace] # Special - passing backtrace through env backtrace = env.delete(:backtrace) end .populate_from_env(env) if backtrace backtrace = backtrace.join("\n") if backtrace.respond_to? :join .backtrace = backtrace else .backtrace = caller.join("\n") end if ignore && ignore.any? { |pattern| if =~ pattern val = Regexp === pattern ? pattern.inspect : pattern.to_s increment_ignore_count(val) true end } return end if Logster.config.enable_custom_patterns_via_ui || allow_custom_patterns custom_ignore = @patterns_cache.fetch(Logster::SuppressionPattern::CACHE_KEY) do Logster::SuppressionPattern.find_all(store: self) end if custom_ignore.any? { |pattern| if =~ pattern increment_ignore_count(pattern.inspect) true end } return end end similar = nil if Logster.config.allow_grouping .( Logster.config., gems_dir: Logster.config.gems_dir, ) key = self.similar_key() similar = get(key, load_env: false) if key end .drop_redundant_envs(Logster.config.) .apply_env_size_limit(Logster.config.max_env_bytes) saved = true if similar similar.() replace_and_bump(similar) similar else .( Logster.config., gems_dir: Logster.config.gems_dir, ) saved = save() end = similar || if (Logster.config.enable_custom_patterns_via_ui || allow_custom_patterns) && saved grouping_patterns = @patterns_cache.fetch(Logster::GroupingPattern::CACHE_KEY) do Logster::GroupingPattern.find_all(store: self) end grouping_patterns.each do |pattern| if =~ pattern group = find_pattern_groups() { |pat| pat == pattern }[0] group ||= Logster::Group.new(pattern.inspect) group.() save_pattern_group(group) if group.changed? break end end end end |
#save(message) ⇒ Object
Save a new message at the front of the latest list.
15 16 17 |
# File 'lib/logster/base_store.rb', line 15 def save() not_implemented end |
#save_pattern_group(group) ⇒ Object
saves an instance of Logster::Group
141 142 143 |
# File 'lib/logster/base_store.rb', line 141 def save_pattern_group(group) 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
26 27 28 |
# File 'lib/logster/base_store.rb', line 26 def similar_key() 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)
86 87 88 |
# File 'lib/logster/base_store.rb', line 86 def solve() not_implemented end |
#unprotect(message_key) ⇒ Object
Clear the protected mark for a message.
80 81 82 |
# File 'lib/logster/base_store.rb', line 80 def unprotect() not_implemented end |