logster 2.12.2 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -0
- data/.streerc +2 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/assets/javascript/{chunk.143.f61340b825c6a3bf6dbe.js → chunk.143.91d07e8cdd5c4b9e4731.js} +4 -4
- data/assets/javascript/{chunk.178.6d9ae01775c898e7b748.js → chunk.178.16d0c9057345120bdba1.js} +3 -3
- data/assets/javascript/client-app.js +1 -1
- data/client-app/package.json +1 -1
- data/client-app/preload-json-manager.rb +10 -17
- data/client-app/yarn.lock +22 -22
- data/lib/examples/sidekiq_logster_reporter.rb +5 -7
- data/lib/logster/base_store.rb +26 -22
- data/lib/logster/cache.rb +2 -1
- data/lib/logster/configuration.rb +3 -3
- data/lib/logster/defer_logger.rb +2 -4
- data/lib/logster/group.rb +17 -20
- data/lib/logster/ignore_pattern.rb +1 -2
- data/lib/logster/logger.rb +18 -16
- data/lib/logster/message.rb +53 -57
- data/lib/logster/middleware/debug_exceptions.rb +12 -10
- data/lib/logster/middleware/reporter.rb +17 -26
- data/lib/logster/middleware/viewer.rb +77 -97
- data/lib/logster/pattern.rb +4 -7
- data/lib/logster/rails/railtie.rb +10 -13
- data/lib/logster/redis_rate_limiter.rb +2 -7
- data/lib/logster/redis_store.rb +79 -99
- data/lib/logster/scheduler.rb +1 -5
- data/lib/logster/suppression_pattern.rb +7 -5
- data/lib/logster/version.rb +1 -1
- data/lib/logster/web.rb +1 -1
- data/lib/logster.rb +15 -17
- data/logster.gemspec +14 -14
- data/test/examples/test_sidekiq_reporter_example.rb +8 -9
- data/test/fake_data/generate.rb +14 -3
- data/test/logster/middleware/test_reporter.rb +9 -7
- data/test/logster/middleware/test_viewer.rb +117 -101
- data/test/logster/test_base_store.rb +79 -58
- data/test/logster/test_cache.rb +5 -11
- data/test/logster/test_defer_logger.rb +3 -3
- data/test/logster/test_group.rb +14 -18
- data/test/logster/test_ignore_pattern.rb +2 -3
- data/test/logster/test_logger.rb +14 -14
- data/test/logster/test_message.rb +29 -31
- data/test/logster/test_pattern.rb +7 -15
- data/test/logster/test_redis_rate_limiter.rb +35 -21
- data/test/logster/test_redis_store.rb +239 -151
- data/test/test_helper.rb +9 -9
- metadata +19 -4
data/lib/logster/pattern.rb
CHANGED
@@ -4,7 +4,8 @@ module Logster
|
|
4
4
|
class Pattern
|
5
5
|
@child_classes = []
|
6
6
|
|
7
|
-
class PatternError < StandardError
|
7
|
+
class PatternError < StandardError
|
8
|
+
end
|
8
9
|
|
9
10
|
def self.inherited(subclass)
|
10
11
|
@child_classes << subclass
|
@@ -23,7 +24,7 @@ module Logster
|
|
23
24
|
return string if Regexp === string
|
24
25
|
return unless String === string
|
25
26
|
if string[0] == "/"
|
26
|
-
return unless string =~
|
27
|
+
return unless string =~ %r{/(.+)/(.*)}
|
27
28
|
string = $1
|
28
29
|
flag = Regexp::IGNORECASE if $2 && $2.include?("i")
|
29
30
|
end
|
@@ -34,11 +35,7 @@ module Logster
|
|
34
35
|
|
35
36
|
def self.find_all(raw: false, store: Logster.store)
|
36
37
|
patterns = store.get_patterns(set_name) || []
|
37
|
-
unless raw
|
38
|
-
patterns.map! do |p|
|
39
|
-
parse_pattern(p)
|
40
|
-
end
|
41
|
-
end
|
38
|
+
patterns.map! { |p| parse_pattern(p) } unless raw
|
42
39
|
patterns.compact!
|
43
40
|
patterns
|
44
41
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Logster::Rails
|
4
|
-
|
5
4
|
# this magically registers logster.js in the asset pipeline
|
6
5
|
class Engine < Rails::Engine
|
7
6
|
end
|
@@ -9,14 +8,14 @@ module Logster::Rails
|
|
9
8
|
def self.set_logger(config)
|
10
9
|
return unless Logster.config.environments.include?(Rails.env.to_sym)
|
11
10
|
|
12
|
-
require
|
13
|
-
require
|
11
|
+
require "logster/middleware/debug_exceptions"
|
12
|
+
require "logster/middleware/reporter"
|
14
13
|
|
15
14
|
store = Logster.store ||= Logster::RedisStore.new
|
16
15
|
store.level = Logger::Severity::WARN if Rails.env.production?
|
17
16
|
|
18
17
|
if Rails.env.development?
|
19
|
-
require
|
18
|
+
require "logster/defer_logger"
|
20
19
|
logger = Logster::DeferLogger.new(store)
|
21
20
|
else
|
22
21
|
logger = Logster::Logger.new(store)
|
@@ -37,9 +36,12 @@ module Logster::Rails
|
|
37
36
|
end
|
38
37
|
|
39
38
|
if Rails::VERSION::MAJOR == 3
|
40
|
-
app.middleware.insert_before ActionDispatch::DebugExceptions,
|
39
|
+
app.middleware.insert_before ActionDispatch::DebugExceptions,
|
40
|
+
Logster::Middleware::DebugExceptions
|
41
41
|
else
|
42
|
-
app.middleware.insert_before ActionDispatch::DebugExceptions,
|
42
|
+
app.middleware.insert_before ActionDispatch::DebugExceptions,
|
43
|
+
Logster::Middleware::DebugExceptions,
|
44
|
+
Rails.application
|
43
45
|
end
|
44
46
|
|
45
47
|
app.middleware.delete ActionDispatch::DebugExceptions
|
@@ -47,18 +49,13 @@ module Logster::Rails
|
|
47
49
|
|
48
50
|
unless Logster.config.application_version
|
49
51
|
git_version = `cd #{Rails.root} && git rev-parse --short HEAD 2> /dev/null`
|
50
|
-
if git_version.present?
|
51
|
-
Logster.config.application_version = git_version.strip
|
52
|
-
end
|
52
|
+
Logster.config.application_version = git_version.strip if git_version.present?
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
class Railtie < ::Rails::Railtie
|
58
|
-
|
59
|
-
config.before_initialize do
|
60
|
-
Logster::Rails.set_logger(config)
|
61
|
-
end
|
58
|
+
config.before_initialize { Logster::Rails.set_logger(config) }
|
62
59
|
|
63
60
|
initializer "logster.configure_rails_initialization" do |app|
|
64
61
|
Logster::Rails.initialize!(app)
|
@@ -81,12 +81,7 @@ module Logster
|
|
81
81
|
private
|
82
82
|
|
83
83
|
def self.key_prefix(redis_prefix)
|
84
|
-
|
85
|
-
"#{redis_prefix.call}:#{PREFIX}"
|
86
|
-
else
|
87
|
-
PREFIX
|
88
|
-
end
|
89
|
-
|
84
|
+
redis_prefix ? "#{redis_prefix.call}:#{PREFIX}" : PREFIX
|
90
85
|
end
|
91
86
|
|
92
87
|
def key_prefix
|
@@ -96,7 +91,7 @@ module Logster
|
|
96
91
|
def mget_keys(bucket_num)
|
97
92
|
keys = @mget_keys.dup
|
98
93
|
keys.delete_at(bucket_num)
|
99
|
-
keys.map { |key| "'#{key}'" }.join(
|
94
|
+
keys.map { |key| "'#{key}'" }.join(", ")
|
100
95
|
end
|
101
96
|
|
102
97
|
def bucket_number(time)
|
data/lib/logster/redis_store.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "json"
|
4
|
+
require "set"
|
5
|
+
require "logster/base_store"
|
6
|
+
require "logster/redis_rate_limiter"
|
7
7
|
|
8
8
|
module Logster
|
9
9
|
class RedisStore < BaseStore
|
@@ -22,9 +22,7 @@ module Logster
|
|
22
22
|
|
23
23
|
def save(message)
|
24
24
|
if keys = message.solved_keys
|
25
|
-
keys.each
|
26
|
-
return false if @redis.hget(solved_key, solved)
|
27
|
-
end
|
25
|
+
keys.each { |solved| return false if @redis.hget(solved_key, solved) }
|
28
26
|
end
|
29
27
|
|
30
28
|
@redis.multi do |pipeline|
|
@@ -97,9 +95,7 @@ module Logster
|
|
97
95
|
def solve(message_key)
|
98
96
|
if (message = get(message_key)) && (keys = message.solved_keys)
|
99
97
|
# add a time so we can expire it
|
100
|
-
keys.each
|
101
|
-
@redis.hset(solved_key, s_key, Time.now.to_f.to_i)
|
102
|
-
end
|
98
|
+
keys.each { |s_key| @redis.hset(solved_key, s_key, Time.now.to_f.to_i) }
|
103
99
|
end
|
104
100
|
clear_solved
|
105
101
|
end
|
@@ -179,19 +175,22 @@ module Logster
|
|
179
175
|
@redis.mapped_hmset(hash_key, protected_messages)
|
180
176
|
(all_keys - protected_keys).each { |k| delete_env(k) }
|
181
177
|
|
182
|
-
sorted =
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
178
|
+
sorted =
|
179
|
+
protected_messages
|
180
|
+
.values
|
181
|
+
.map do |string|
|
182
|
+
begin
|
183
|
+
Message.from_json(string)
|
184
|
+
rescue StandardError
|
185
|
+
nil
|
186
|
+
end
|
187
|
+
end
|
188
|
+
.compact
|
189
|
+
.sort
|
190
|
+
.map(&:key)
|
190
191
|
|
191
192
|
@redis.pipelined do |pipeline|
|
192
|
-
sorted.each
|
193
|
-
pipeline.rpush(list_key, message_key)
|
194
|
-
end
|
193
|
+
sorted.each { |message_key| pipeline.rpush(list_key, message_key) }
|
195
194
|
end
|
196
195
|
|
197
196
|
find_pattern_groups(load_messages: true).each do |group|
|
@@ -212,9 +211,7 @@ module Logster
|
|
212
211
|
@redis.del(solved_key)
|
213
212
|
@redis.del(ignored_logs_count_key)
|
214
213
|
@redis.del(pattern_groups_key)
|
215
|
-
Logster::Pattern.child_classes.each
|
216
|
-
@redis.del(klass.set_name)
|
217
|
-
end
|
214
|
+
Logster::Pattern.child_classes.each { |klass| @redis.del(klass.set_name) }
|
218
215
|
@redis.keys.each do |key|
|
219
216
|
@redis.del(key) if key.include?(Logster::RedisRateLimiter::PREFIX)
|
220
217
|
@redis.del(key) if key.start_with?(ip_rate_limit_key(""))
|
@@ -226,9 +223,7 @@ module Logster
|
|
226
223
|
return nil unless json
|
227
224
|
|
228
225
|
message = Message.from_json(json)
|
229
|
-
if load_env
|
230
|
-
message.env = get_env(message_key) || {}
|
231
|
-
end
|
226
|
+
message.env = get_env(message_key) || {} if load_env
|
232
227
|
message
|
233
228
|
end
|
234
229
|
|
@@ -249,26 +244,30 @@ module Logster
|
|
249
244
|
envs = nil
|
250
245
|
if with_env
|
251
246
|
envs = {}
|
252
|
-
@redis
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
next if !json || json.size == 0
|
263
|
-
message = Message.from_json(json)
|
264
|
-
if with_env && envs
|
265
|
-
env = envs[message.key]
|
266
|
-
if !message.env || message.env.size == 0
|
267
|
-
message.env = env || {}
|
247
|
+
@redis
|
248
|
+
.eval(
|
249
|
+
BULK_ENV_GET_LUA,
|
250
|
+
keys: message_keys.map { |k| env_prefix(k, with_namespace: true) },
|
251
|
+
)
|
252
|
+
.to_h
|
253
|
+
.each do |k, v|
|
254
|
+
next if v.size == 0
|
255
|
+
parsed = v.size == 1 ? JSON.parse(v[0]) : v.map { |e| JSON.parse(e) }
|
256
|
+
envs[env_unprefix(k, with_namespace: true)] = parsed
|
268
257
|
end
|
269
|
-
end
|
270
|
-
message
|
271
258
|
end
|
259
|
+
messages =
|
260
|
+
@redis
|
261
|
+
.hmget(hash_key, message_keys)
|
262
|
+
.map! do |json|
|
263
|
+
next if !json || json.size == 0
|
264
|
+
message = Message.from_json(json)
|
265
|
+
if with_env && envs
|
266
|
+
env = envs[message.key]
|
267
|
+
message.env = env || {} if !message.env || message.env.size == 0
|
268
|
+
end
|
269
|
+
message
|
270
|
+
end
|
272
271
|
messages.compact!
|
273
272
|
messages
|
274
273
|
end
|
@@ -308,7 +307,7 @@ module Logster
|
|
308
307
|
end
|
309
308
|
|
310
309
|
def redis_prefix
|
311
|
-
return
|
310
|
+
return "default".freeze if !@redis_prefix
|
312
311
|
@prefix_is_proc ||= @redis_prefix.respond_to?(:call)
|
313
312
|
@prefix_is_proc ? @redis_prefix.call : @redis_prefix
|
314
313
|
end
|
@@ -345,28 +344,26 @@ module Logster
|
|
345
344
|
key = ip_rate_limit_key(ip_address)
|
346
345
|
|
347
346
|
limited = @redis.call([:exists, key])
|
348
|
-
if Integer === limited
|
349
|
-
limited = limited != 0
|
350
|
-
end
|
347
|
+
limited = limited != 0 if Integer === limited
|
351
348
|
|
352
|
-
if perform && !limited
|
353
|
-
@redis.setex key, limit, ""
|
354
|
-
end
|
349
|
+
@redis.setex key, limit, "" if perform && !limited
|
355
350
|
|
356
351
|
limited
|
357
352
|
end
|
358
353
|
|
359
354
|
def find_pattern_groups(load_messages: false)
|
360
|
-
patterns =
|
361
|
-
Logster::GroupingPattern
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
355
|
+
patterns =
|
356
|
+
@patterns_cache.fetch(Logster::GroupingPattern::CACHE_KEY) do
|
357
|
+
Logster::GroupingPattern.find_all(store: self)
|
358
|
+
end
|
359
|
+
patterns =
|
360
|
+
patterns.select do |pattern|
|
361
|
+
if block_given?
|
362
|
+
yield(pattern)
|
363
|
+
else
|
364
|
+
true
|
365
|
+
end
|
368
366
|
end
|
369
|
-
end
|
370
367
|
return [] if patterns.size == 0
|
371
368
|
mapped = patterns.map(&:inspect)
|
372
369
|
jsons = @redis.hmget(pattern_groups_key, mapped)
|
@@ -374,9 +371,7 @@ module Logster
|
|
374
371
|
if json && json.size > 0
|
375
372
|
group = Logster::Group.from_json(json)
|
376
373
|
group.pattern = patterns[mapped.index(group.key)]
|
377
|
-
if load_messages
|
378
|
-
group.messages = bulk_get(group.messages_keys, with_env: false)
|
379
|
-
end
|
374
|
+
group.messages = bulk_get(group.messages_keys, with_env: false) if load_messages
|
380
375
|
group
|
381
376
|
end
|
382
377
|
end
|
@@ -405,9 +400,7 @@ module Logster
|
|
405
400
|
message_keys = @redis.lrange(list_key, 0, -1) || []
|
406
401
|
|
407
402
|
bulk_get(message_keys).each do |message|
|
408
|
-
unless (ignores & (message.solved_keys || [])).empty?
|
409
|
-
delete message
|
410
|
-
end
|
403
|
+
delete message unless (ignores & (message.solved_keys || [])).empty?
|
411
404
|
end
|
412
405
|
end
|
413
406
|
end
|
@@ -424,9 +417,7 @@ module Logster
|
|
424
417
|
removed_keys << removed_key
|
425
418
|
end
|
426
419
|
end
|
427
|
-
removed_keys.reverse.each
|
428
|
-
@redis.lpush(list_key, key)
|
429
|
-
end
|
420
|
+
removed_keys.reverse.each { |key| @redis.lpush(list_key, key) }
|
430
421
|
end
|
431
422
|
end
|
432
423
|
|
@@ -465,7 +456,7 @@ module Logster
|
|
465
456
|
start = -limit
|
466
457
|
finish = -1
|
467
458
|
|
468
|
-
return
|
459
|
+
return start, finish unless before || after
|
469
460
|
|
470
461
|
found = nil
|
471
462
|
find = before || after
|
@@ -527,11 +518,7 @@ module Logster
|
|
527
518
|
if Array === message.env
|
528
519
|
array_env_matches?(message, search, exclude)
|
529
520
|
else
|
530
|
-
|
531
|
-
!env_matches?(message.env, search)
|
532
|
-
else
|
533
|
-
env_matches?(message.env, search)
|
534
|
-
end
|
521
|
+
exclude ? !env_matches?(message.env, search) : env_matches?(message.env, search)
|
535
522
|
end
|
536
523
|
end
|
537
524
|
|
@@ -547,7 +534,7 @@ module Logster
|
|
547
534
|
value.to_s =~ search
|
548
535
|
when String
|
549
536
|
value.to_s =~ Regexp.new(search, Regexp::IGNORECASE)
|
550
|
-
|
537
|
+
else
|
551
538
|
false
|
552
539
|
end
|
553
540
|
end
|
@@ -555,13 +542,10 @@ module Logster
|
|
555
542
|
end
|
556
543
|
|
557
544
|
def array_env_matches?(message, search, exclude)
|
558
|
-
matches =
|
559
|
-
|
560
|
-
!env_matches?(env, search)
|
561
|
-
else
|
562
|
-
env_matches?(env, search)
|
545
|
+
matches =
|
546
|
+
message.env.select do |env|
|
547
|
+
exclude ? !env_matches?(env, search) : env_matches?(env, search)
|
563
548
|
end
|
564
|
-
end
|
565
549
|
return false if matches.empty?
|
566
550
|
message.env = matches
|
567
551
|
message.count = matches.size
|
@@ -619,22 +603,22 @@ module Logster
|
|
619
603
|
# when you hit load more and the first row is a group.
|
620
604
|
# The server uses this info (row_id) to know where it needs to
|
621
605
|
# start scanning messages when looking up older messages.
|
622
|
-
Logster::Group::GroupWeb.new(
|
623
|
-
group.key,
|
624
|
-
group.count,
|
625
|
-
group.timestamp,
|
626
|
-
group.messages,
|
627
|
-
row_id
|
628
|
-
)
|
606
|
+
Logster::Group::GroupWeb.new(group.key, group.count, group.timestamp, group.messages, row_id)
|
629
607
|
end
|
630
608
|
|
631
609
|
def register_rate_limit(severities, limit, duration, callback)
|
632
610
|
severities = [severities] unless severities.is_a?(Array)
|
633
611
|
redis = (@redis_raw_connection && @redis_prefix) ? @redis_raw_connection : @redis
|
634
612
|
|
635
|
-
rate_limiter =
|
636
|
-
|
637
|
-
|
613
|
+
rate_limiter =
|
614
|
+
RedisRateLimiter.new(
|
615
|
+
redis,
|
616
|
+
severities,
|
617
|
+
limit,
|
618
|
+
duration,
|
619
|
+
Proc.new { redis_prefix },
|
620
|
+
callback,
|
621
|
+
)
|
638
622
|
|
639
623
|
rate_limits[self.redis_prefix] ||= []
|
640
624
|
rate_limits[self.redis_prefix] << rate_limiter
|
@@ -654,17 +638,13 @@ module Logster
|
|
654
638
|
|
655
639
|
def env_unprefix(key, with_namespace: false)
|
656
640
|
prefix = ENV_PREFIX
|
657
|
-
if with_namespace && namespace
|
658
|
-
prefix = "#{namespace}:#{prefix}"
|
659
|
-
end
|
641
|
+
prefix = "#{namespace}:#{prefix}" if with_namespace && namespace
|
660
642
|
key.sub(prefix, "")
|
661
643
|
end
|
662
644
|
|
663
645
|
def env_prefix(key, with_namespace: false)
|
664
646
|
prefix = ENV_PREFIX
|
665
|
-
if with_namespace && namespace
|
666
|
-
prefix = "#{namespace}:#{prefix}"
|
667
|
-
end
|
647
|
+
prefix = "#{namespace}:#{prefix}" if with_namespace && namespace
|
668
648
|
prefix + key
|
669
649
|
end
|
670
650
|
|
data/lib/logster/scheduler.rb
CHANGED
@@ -24,12 +24,14 @@ module Logster
|
|
24
24
|
def retro_delete_messages
|
25
25
|
keys = []
|
26
26
|
grouping_keys = []
|
27
|
-
@store
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
@store
|
28
|
+
.get_all_messages(with_env: false)
|
29
|
+
.each do |message|
|
30
|
+
if message =~ self.pattern
|
31
|
+
keys << message.key
|
32
|
+
grouping_keys << message.grouping_key
|
33
|
+
end
|
31
34
|
end
|
32
|
-
end
|
33
35
|
@store.bulk_delete(keys, grouping_keys) if keys.size > 0 && grouping_keys.size > 0
|
34
36
|
end
|
35
37
|
end
|
data/lib/logster/version.rb
CHANGED
data/lib/logster/web.rb
CHANGED
data/lib/logster.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
|
15
|
-
if defined?
|
16
|
-
require
|
3
|
+
require "logster/version"
|
4
|
+
require "logster/logger"
|
5
|
+
require "logster/message"
|
6
|
+
require "logster/configuration"
|
7
|
+
require "logster/web"
|
8
|
+
require "logster/ignore_pattern"
|
9
|
+
require "logster/pattern"
|
10
|
+
require "logster/suppression_pattern"
|
11
|
+
require "logster/grouping_pattern"
|
12
|
+
require "logster/group"
|
13
|
+
require "logster/cache"
|
14
|
+
|
15
|
+
if defined?(Redis)
|
16
|
+
require "logster/redis_store"
|
17
17
|
else
|
18
18
|
STDERR.puts "ERROR: Redis is not loaded, ensure redis gem is required before logster"
|
19
19
|
exit
|
@@ -57,6 +57,4 @@ end
|
|
57
57
|
# check logster/configuration.rb for config options
|
58
58
|
# Logster.config.environments << :staging
|
59
59
|
|
60
|
-
if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
|
61
|
-
require 'logster/rails/railtie'
|
62
|
-
end
|
60
|
+
require "logster/rails/railtie" if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
|
data/logster.gemspec
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
lib = File.expand_path(
|
4
|
+
lib = File.expand_path("../lib", __FILE__)
|
5
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require
|
6
|
+
require "logster/version"
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name
|
10
|
-
spec.version
|
11
|
-
spec.authors
|
12
|
-
spec.email
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
16
|
-
spec.license
|
9
|
+
spec.name = "logster"
|
10
|
+
spec.version = Logster::VERSION
|
11
|
+
spec.authors = ["Sam Saffron"]
|
12
|
+
spec.email = ["sam.saffron@gmail.com"]
|
13
|
+
spec.summary = "UI for viewing logs in Rack"
|
14
|
+
spec.description = "UI for viewing logs in Rack"
|
15
|
+
spec.homepage = "https://github.com/discourse/logster"
|
16
|
+
spec.license = "MIT"
|
17
17
|
|
18
18
|
spec.required_ruby_version = ">= 2.5.0"
|
19
19
|
|
20
|
-
files =
|
21
|
-
`git ls-files -z`.split("\x0").reject { |f| f.start_with?(/website|bin/) }
|
20
|
+
files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?(/website|bin/) }
|
22
21
|
files += Dir.glob("assets/javascript/*")
|
23
22
|
files += Dir.glob("assets/stylesheets/*")
|
24
23
|
spec.files = files
|
25
24
|
|
26
|
-
spec.executables
|
27
|
-
spec.test_files
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
27
|
spec.require_paths = ["lib"]
|
29
28
|
|
30
29
|
# NOTE dependency on rack is not explicit, this enables us to use
|
@@ -39,4 +38,5 @@ Gem::Specification.new do |spec|
|
|
39
38
|
spec.add_development_dependency "timecop"
|
40
39
|
spec.add_development_dependency "byebug", "~> 11.1.0"
|
41
40
|
spec.add_development_dependency "rubocop-discourse", "~> 2.4.1"
|
41
|
+
spec.add_development_dependency "syntax_tree"
|
42
42
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/logger"
|
5
|
+
require "logster/redis_store"
|
6
|
+
require "logger"
|
7
|
+
require "examples/sidekiq_logster_reporter"
|
8
8
|
|
9
9
|
class TestSidekiqReporter < MiniTest::Test
|
10
|
-
|
11
10
|
def setup
|
12
11
|
Logster.store = @store = Logster::RedisStore.new(Redis.new)
|
13
12
|
Logster.logger = @logger = Logster::Logger.new(Logster.store)
|
@@ -38,11 +37,11 @@ class TestSidekiqReporter < MiniTest::Test
|
|
38
37
|
# A backtrace is joined()
|
39
38
|
assert_equal(trace.join("\n"), report.backtrace)
|
40
39
|
# The backtrace is deleted from the env
|
41
|
-
assert_nil(report.env[
|
40
|
+
assert_nil(report.env["backtrace"])
|
42
41
|
assert_nil(report.env[:backtrace])
|
43
42
|
|
44
43
|
# The env is in the report
|
45
|
-
assert_equal("Test", report.env[
|
46
|
-
assert_equal(20, report.env[
|
44
|
+
assert_equal("Test", report.env["code"])
|
45
|
+
assert_equal(20, report.env["params"]["article_id"])
|
47
46
|
end
|
48
47
|
end
|
data/test/fake_data/generate.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "redis"
|
4
|
+
require "logster"
|
5
5
|
|
6
6
|
Logster.config.allow_grouping = true
|
7
7
|
Logster.config.application_version = "ABC123"
|
8
8
|
Logster.store = Logster::RedisStore.new
|
9
9
|
|
10
10
|
10.times do
|
11
|
-
Logster.store.report(
|
11
|
+
Logster.store.report(
|
12
|
+
Logger::WARN,
|
13
|
+
"application",
|
14
|
+
"test warning",
|
15
|
+
backtrace: "method1\nmethod2",
|
16
|
+
env: {
|
17
|
+
something: ["hello world", "hello places"],
|
18
|
+
another: {
|
19
|
+
thing: "something else",
|
20
|
+
},
|
21
|
+
},
|
22
|
+
)
|
12
23
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require_relative "../../test_helper"
|
4
|
+
require "rack"
|
5
|
+
require "logster/redis_store"
|
6
|
+
require "logster/middleware/reporter"
|
7
7
|
|
8
8
|
class TestReporter < Minitest::Test
|
9
|
-
|
10
9
|
def setup
|
11
10
|
Logster.store = Logster::RedisStore.new
|
12
11
|
Logster.store.clear_all
|
@@ -72,11 +71,14 @@ class TestReporter < Minitest::Test
|
|
72
71
|
assert_equal(1, Logster.store.count)
|
73
72
|
|
74
73
|
reporter = Logster::Middleware::Reporter.new(nil)
|
75
|
-
env =
|
74
|
+
env =
|
75
|
+
Rack::MockRequest.env_for(
|
76
|
+
"/logs/report_js_error?message=hello2",
|
77
|
+
"REMOTE_ADDR" => "100.1.1.2",
|
78
|
+
)
|
76
79
|
status, = reporter.call(env)
|
77
80
|
|
78
81
|
assert_equal(200, status)
|
79
82
|
assert_equal(2, Logster.store.count)
|
80
83
|
end
|
81
|
-
|
82
84
|
end
|